Expand description
yash-executor
is a library for running concurrent tasks in a
single-threaded context. This crate supports no_std
configurations but
requires the alloc
crate.
The Executor
provided by this crate can be instantiated more than once
to run multiple sets of tasks concurrently. Each executor maintains its
own set of tasks and does not share tasks with other executors. This is
different from other executor implementations that use a global or
thread-local executor.
This crate is free of locks and atomic operations at the cost of unsafe spawning. Wakers used in this crate are thread-unsafe and not guarded by locks or atomics, so you must ensure that wakers are not shared between threads.
let executor = Executor::new();
// Spawn a task that returns 42
let receiver = unsafe { executor.spawn(async { 42 }) };
// The task is not yet complete
assert_eq!(receiver.try_receive(), Err(TryReceiveError::NotSent));
// Run the executor until the task is complete
executor.run_until_stalled();
// Now we have the result
assert_eq!(receiver.try_receive(), Ok(42));
Spawner
s provide a subset of the functionality of Executor
to allow
spawning tasks without access to the full executor. It is useful for adding
tasks from within another task without creating cyclic dependencies, which
can cause memory leaks.
The forwarder
module provides utilities for forwarding the result of a
future to another future. The forwarder
function
creates a pair of Sender
and Receiver
that share an internal state
to communicate the result of a future. A Receiver
is also returned from
the Executor::spawn
method to receive the result of a future.
Modules§
- forwarder
- Utilities for forwarding the result of a future to another future
Structs§
- Executor
- Interface for running concurrent tasks
- Spawn
Error - Error returned when a task cannot be spawned
- Spawner
- Interface for spawning tasks