Skip to main content

Module task

Module task 

Source
Expand description

Tasks: spawning, their handles and ids, cancellation from anywhere, and yielding. Tasks: spawning (named, or on a worker the caller names, or neither), their handles and ids, cancellation from anywhere, and yielding to the other tasks of the shard.

Re-exports§

pub use crate::runtime::spawn;
pub use crate::runtime::spawn_blocking;
pub use crate::runtime::spawn_local;

Modules§

coop
Cooperative scheduling: the budget of operations each poll of a task may complete before it yields to the other tasks of its shard. IO that completes spends one, and so do the receives, acquires and locks of sync that complete without queueing (see its module docs).

Structs§

AbortHandle
Cancels a task from anywhere: made by Task::abort_handle, cloned and sent freely, and it outlives the Task. It keeps the task’s memory, not its future: an aborted task’s future is dropped where the task runs.
AccessError
The key was read where no scope set it.
Builder
Spawns tasks with options: a name, kept with the task’s id while the task lives and shown to the runtime’s task hooks (TaskMeta::name), and the worker to place it on. Every spawn answers an error where the free functions panic.
FallibleTask
A spawned task whose output is None when the task ended without one.
Id
A task’s id: unique among the tasks of the process, never reused.
Join
The future of Task::join: the task’s output, or why there is none.
JoinError
Why a task gave no output: it was cancelled (by its handle, an AbortHandle, or its runtime shutting down), or its future panicked.
JoinSet
A set of spawned tasks, joined in the order they finish.
LocalKey
A task-local key, declared with task_local!.
Task
A spawned task.
TaskLocalFuture
The future of LocalKey::scope.

Functions§

id
The id of the task this code runs in.
try_id
The id of the task this code runs in, None outside a task (in block_on’s own future, or on a blocking-pool thread).
yield_now
Gives the other tasks of this shard a turn: the task goes to the back of its shard’s run queue and runs again after the tasks queued before it. In block_on’s own future it lets the shard run its queue once.