Skip to main content

Task

Struct Task 

Source
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: u64

Trace 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: usize

Position in spawn order within that scope, counting from one.

§state: RefCell<TaskState>

Implementations§

Source§

impl Task

Source

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.

Source

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.

Source

pub fn is_running(&self) -> bool

Whether the body is still running on its own thread.

Source

pub fn is_cancelled(&self) -> bool

Whether this task’s own cancellation was requested.

Source

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.

Source

pub fn join(&self)

Waits for the body’s thread and records what it produced, unless the task has already been joined.

A task’s body runs at most once and is joined at most once, so awaiting the same handle twice returns the same value and repeats no effect.

Source

pub fn describe(&self) -> String

How this task is named in diagnostics.

Trait Implementations§

Source§

impl Debug for Task

A task shows as what it is, never as the value it will produce: that value is observable through await or scope exit and through nothing else.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Task

§

impl !RefUnwindSafe for Task

§

impl !Send for Task

§

impl !Sync for Task

§

impl !UnwindSafe for Task

§

impl Unpin for Task

§

impl UnsafeUnpin for Task

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.