The two classes represent excellent abstractions for concurrent programming, so it's a bit disconcerting that they don't support the same API.
Specifically, according to the docs:
asyncio.Future
is almost compatible withconcurrent.futures.Future
.Differences:
result()
andexception()
do not take a timeout argument and raise an exception when the future isn’t done yet.- Callbacks registered with
add_done_callback()
are always called via the event loop'scall_soon_threadsafe()
.- This class is not compatible with the
wait()
andas_completed()
functions in theconcurrent.futures
package.
The above list is actually incomplete, there are a couple more differences:
running()
method is absentresult()
andexception()
may raiseInvalidStateError
if called too early
Are any of these due to the inherent nature of an event loop that makes these operations either useless or too troublesome to implement?
And what is the meaning of the difference related to add_done_callback()
? Either way, the callback is guaranteed to happen at some unspecified time after the futures is done, so isn't it perfectly consistent between the two classes?