pub struct Task {
pub id: u64,
pub scope: Rc<str>,
pub position: usize,
pub state: RefCell<TaskState>,
/* private fields */
}Expand description
A spawned unit of work and the value it will produce.
The value is reachable only through TaskState::Settled, so no caller
can observe it without going through await or scope exit.
Fields§
§id: u64Trace identity, unique across the run. Zero for a task that was already settled when it was created, which never appears in a trace because it never ran as a task.
scope: Rc<str>The name of the scope that owns this task, for diagnostics.
position: usizePosition in spawn order within that scope, counting from one.
state: RefCell<TaskState>Implementations§
Source§impl Task
impl Task
Sourcepub fn running(
id: u64,
scope: Rc<str>,
position: usize,
cancellation: Cancellation,
thread: JoinHandle<TaskOutcome>,
) -> Rc<Task>
pub fn running( id: u64, scope: Rc<str>, position: usize, cancellation: Cancellation, thread: JoinHandle<TaskOutcome>, ) -> Rc<Task>
A task whose body is already running on thread.
Sourcepub fn settled(value: Value) -> Rc<Task>
pub fn settled(value: Value) -> Rc<Task>
A task whose value is already known.
An async fn is called like any other function and runs its body at
the call site, so the handle it returns is settled on creation. ADR
0008 gives a thread to spawn, which is where the language says
concurrency begins; nothing may depend on when an async fn body ran,
only on the value await produces.
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the body is still running on its own thread.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Whether this task’s own cancellation was requested.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Asks this task to stop at its next safepoint.
A task that has already finished is unaffected: cancellation stops
work that has not happened, it does not undo work that has. Nothing
here waits — Task::join is what waits — because a scope cancels
all of its children before waiting for any of them.