Dealing with Asyncio and Futures
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.
Getting ready
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 ...
Get Python Parallel Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.