A Waker is the executor handle associated with a pending asynchronous task. Calling it tells the Tokio runtime to poll that task again when its result may be ready. section 10.4 section 10.6
A custom Future uses the Waker through its poll contract:
- Return Poll::Pending when the computation cannot yet produce its value. section 10.4
- Register the task through the current Context when external work must complete first. section 10.4
- Call cx.waker().wake_by_ref() or wake() when the task should be scheduled again. section 10.5
- Return Poll::Ready(value) once the computation has completed. section 10.4
Waking a custom timer
An AsyncTimer compares Instant::now() with its expiration time. Before expiration, it clones the Waker, starts a thread that sleeps until the deadline, returns Poll::Pending, and later calls wake(). The executor then polls the timer again, allowing it to return Poll::Ready with its completion string. section 10.5
