Bug: 180427432

Clone this repo:
  1. 4f3e765 Update TEST_MAPPING by Jeff Vander Stoep · 7 days ago master
  2. 72f0890 Update TEST_MAPPING by David Brazdil · 13 days ago
  3. 7e800ae Upgrade async_task to 4.3.0 am: 1d8091d3e6 by Jeff Vander Stoep · 9 weeks ago main-16k-with-phones
  4. 1d8091d Upgrade async_task to 4.3.0 by Jeff Vander Stoep · 9 weeks ago
  5. d0c5041 Upgrade rust/crates/async-task to 4.2.0 am: 549375c924 am: 5ba6603fdd am: 3e470bf5f7 am: db51179e4b by David LeGare · 8 months ago


Build License Cargo Documentation

Task abstraction for building executors.

To spawn a future onto an executor, we first need to allocate it on the heap and keep some state attached to it. The state indicates whether the future is ready for polling, waiting to be woken up, or completed. Such a stateful future is called a task.

All executors have a queue that holds scheduled tasks:

let (sender, receiver) = flume::unbounded();

A task is created using either spawn(), spawn_local(), or spawn_unchecked() which return a Runnable and a Task:

// A future that will be spawned.
let future = async { 1 + 2 };

// A function that schedules the task when it gets woken up.
let schedule = move |runnable| sender.send(runnable).unwrap();

// Construct a task.
let (runnable, task) = async_task::spawn(future, schedule);

// Push the task into the queue by invoking its schedule function.

The Runnable is used to poll the task's future, and the Task is used to await its output.

Finally, we need a loop that takes scheduled tasks from the queue and runs them:

for runnable in receiver {

Method run() polls the task's future once. Then, the Runnable vanishes and only reappears when its Waker wakes the task, thus scheduling it to be run again.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.