liveBook · Manning

Waker

As explained in Rust Servers, Services, and Apps

A Rust Waker is a handle that allows an asynchronous computation to notify its executor that it should be polled again.

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

How Rust Servers, Services, and Apps covers it

How deep it goes
Explains Waker through custom Future implementations, Poll states, and a timer, but does not detail executor internals.
Examples
Uses a repeatedly awakened file future and an expiration-based AsyncTimer alongside Tokio-spawned tasks.
What it assumes
Assumes familiarity with async computations and Rust futures while treating Pin as an advanced technical requirement.
What you can do after
Build it from scratch by implementing a Future that returns Poll::Pending, stores a Waker, and wakes the executor after external work.
How it connects
Connects Waker to futures, the Future trait, poll, Context, Poll, asynchronous runtimes, and the Tokio executor.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.