Struct crs_bind::rtos::Context[][src]

pub struct Context(_);

Represents an ongoing operation which could be cancelled in the future. Inspired by contexts in the Go programming language.

Concepts

Contexts have a few important concepts: “cancellation”, “parent” and “deadline”. A context can be cancelled by calling its Context::cancel() method; this notifies any tasks which are waiting on its Context::done() event. It is also cancelled automatically if and when its parent context is cancelled, and when the last copy of it goes out of scope. A “deadline” allows a context to be automatically cancelled at a certain timestamp; this is implemented without creating extra tasks/threads.

Forking

A context can be “forked”, which creates a new child context. This new context can optionally be created with a deadline.

Implementations

impl Context[src]

pub fn new_global() -> Self[src]

Creates a new global context (i.e., one which has no parent or deadline).

pub fn cancel(&self)[src]

Cancels a context. This is a no-op if the context is already cancelled.

pub fn fork(&self) -> Self[src]

Forks a context. The new context’s parent is self.

pub fn fork_with_deadline(&self, deadline: Instant) -> Self[src]

Forks a context. Equivalent to Context::fork(), except that the new context has a deadline which is the earlier of the one in self and the one provided.

pub fn fork_with_timeout(&self, timeout: Duration) -> Self[src]

Forks a context. Equivalent to Context::fork_with_deadline(), except that the deadline is calculated from the current time and the provided timeout duration.

pub fn done(&self) -> impl Selectable + '_[src]

A Selectable event which occurs when the context is cancelled. The sleep amount takes the context deadline into consideration.

Trait Implementations

impl Clone for Context[src]

Auto Trait Implementations

impl Send for Context

impl Sync for Context

impl Unpin for Context

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.