Another key component of the Asyncio module is the Future
class. This is very similar to concurrent.futures.Futures
, but of course, it is adapted in the main mechanism of Asyncio's event loop. The asyncio.Future
class represents a result (but can also be an exception) that is not yet available. It therefore represents an abstraction of something that is yet to be accomplished.
Callbacks that have to process any results are in fact added to the instances of this class.
To manage an object Future
in Asyncio, we must declare the following:
import asyncio future = asyncio.Future()
The basic methods of this class are:
cancel()
: This cancels the future and schedules callbacksresult()
: This returns the result that this future representsexception()
: This returns the exception that was set on this futureadd_done_callback(fn)
: This adds a callback that is to be run whenfuture
is executedremove_done_callback(fn)
: This removes all instances of a callback...