Struct crs_bind::rtos::Promise[][src]

pub struct Promise<T: 'static = ()>(_);

Represents an ongoing operation which produces a result.

Implementations

impl<T: 'static> Promise<T>[src]

pub fn new() -> (Self, impl FnOnce(T))[src]

Creates a new lightweight promise and an associated resolve function.

Example

let (promise, resolve) = Promise::<i32>::new();
Task::spawn(|| {
    Task::delay(Duration::from_secs(1));
    resolve(10);
})
.unwrap();
println!(
    "n = {}",
    select! {
        n = promise.done() => n,
    }
);

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

A Selectable event which occurs when the promise is resolved.

impl<T: Send + Sync + 'static> Promise<T>[src]

pub fn spawn(f: impl FnOnce() -> T + Send + 'static) -> Self[src]

Spawns a task to run the given function and returns a Promise that resolves with the result when it returns. Panics on failure; see Promise::try_spawn().

pub fn try_spawn(f: impl FnOnce() -> T + Send + 'static) -> Result<Self, Error>[src]

Spawns a task to run the given function and returns a Promise that resolves with the result when it returns.

pub fn then<U: Send + Sync + 'static>(
    &self,
    f: impl FnOnce(&T) -> U + Send + 'static
) -> Promise<U>
[src]

Spawns a new promise which, upon the completion of self, runs f.

pub fn then_or<U: Send + Sync + 'static>(
    &self,
    ctx: Context,
    default: U,
    f: impl FnOnce(&T) -> U + Send + 'static
) -> Promise<U>
[src]

Spawns a new promise which, upon the completion of self, runs f. If ctx is cancelled before self completes, the result is default.

pub fn then_some<U: Send + Sync + 'static>(
    &self,
    ctx: Context,
    f: impl FnOnce(&T) -> U + Send + 'static
) -> Promise<Option<U>>
[src]

Spawns a new promise which, upon the completion of self, runs f. If ctx is cancelled before self completes, the result is None.

Trait Implementations

impl<T: 'static> Clone for Promise<T>[src]

Auto Trait Implementations

impl<T> Send for Promise<T> where
    T: Send + Sync

impl<T> Sync for Promise<T> where
    T: Send + Sync

impl<T> Unpin for Promise<T>

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.