Bug: 180427432

Clone this repo:
  1. e56e407 Upgrade async_task to 4.5.0 am: 36665bc1d1 by Jeff Vander Stoep · 3 months ago main master
  2. 36665bc Upgrade async_task to 4.5.0 by Jeff Vander Stoep · 3 months ago
  3. f02ee5a Migrate to cargo_embargo. am: 93b21ad4eb by Andrew Walbran · 5 months ago
  4. 93b21ad Migrate to cargo_embargo. by Andrew Walbran · 5 months ago
  5. 7a63e86 Make async-task available to product and vendor am: e7cd2b3885 am: e931a5f787 am: d0024473d3 am: 4d4b2dbe48 by Matthew Maurer · 12 months ago android14-qpr1-release android14-qpr1-s2-release android-14.0.0_r16 android-14.0.0_r17 android-14.0.0_r18 android-14.0.0_r19 android-14.0.0_r20 android-14.0.0_r21 android-14.0.0_r22 android-14.0.0_r23 android-14.0.0_r24 android-14.0.0_r25 android-14.0.0_r26 android-14.0.0_r27


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.