4 ms·
> if a future is inert, how can it ever detect that it is ready to make progress and call wake This is the crux, and I wish the discussion started by posing an
by millstone 6y ago
> if a future is inert, how can it ever detect that it is ready to make progress and call wake
This is the crux, and I wish the discussion started by posing and answering this question.
Futures are NOT inert. This is referenced only obliquely:
When a future is not ready yet, poll returns Poll::Pending and stores a clone of the Waker copied from the current Context. This Waker is then woken once the future can make progress
The passive voice "the waker is woken" obscures the fact that the Future itself is responsible for arranging the call to wake(). This means that the Future maintains some sort of dual active presence: it owns a thread, or a timer, or adds a file descriptor to an fd set, etc.
An example from futures::io::AsyncRead::poll:
If no data is available for reading, the method returns Poll::Pending and arranges for the current task to receive a notification when the object becomes readable or is closed.
So `poll()` is a misleading name: it is not a passive check but a hook for the Future to materialize its dual, active half.
- Arnavion 6y agoThe waking is done by the executor. You can call the executor the "dual active presence" of the future or whatever if you want. I think it would be misleading because there's only one executor and there are many futures.