Future & Tasks
Explore how Futures represent asynchronous computations that will complete in the future and how Tasks wrap coroutines to run in event loops. Understand how these asyncio constructs enable cooperative multitasking, allow coroutines to wait for results, and how tasks can be created, scheduled, and cancelled. This lesson helps you grasp core async programming building blocks essential for Python concurrency.
We'll cover the following...
Futures & Tasks
Future
Future represents a computation that is either in progress or will get scheduled in the future. It is a special low-level awaitable object that represents an eventual result of an asynchronous operation. Don't confuse threading.Future and asyncio.Future. The former is part of the threading module and doesn't have an __iter__() method defined on it. asyncio.Future is an awaitable and can be used with the yield from statement. In ...