tag | bc19f16328e47598d719eaa13d9602428db85983 | |
---|---|---|
tagger | The Android Open Source Project <initial-contribution@android.com> | Wed Nov 01 17:06:47 2023 -0700 |
object | 543b474561e4010b2c07624d85ad2a8e5d7ee761 |
frc_340819190 (10894928,com.google.android.healthfitness)
commit | 543b474561e4010b2c07624d85ad2a8e5d7ee761 | [log] [tgz] |
---|---|---|
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Tue Apr 11 17:56:45 2023 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Tue Apr 11 17:56:45 2023 +0000 |
tree | 920f690346620be8f3e538141249f6331fa01d4e | |
parent | 9dcac8690362d74130af4907ca527c0378cfb0bd [diff] | |
parent | b0b6d6d093eddeae1844e0a4a8e60347447ffa56 [diff] |
Snap for 9912757 from b0b6d6d093eddeae1844e0a4a8e60347447ffa56 to aml-frc-release Change-Id: Ia5e146f4ddd1464cfc8aaf5fda8a91137b8260ec
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. runnable.schedule();
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 { runnable.run(); }
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.