Struct gj::Promise [] [src]

#[must_use]
pub struct Promise<T, E> where T: 'static, E: 'static {
    // some fields omitted
}

A computation that might eventually resolve to a value of type T or to an error of type E.

Methods

impl<T, E> Promise<T, E>
[src]

fn then_else<F, R, E1>(self, func: F) -> Promise<R, E1> where F: 'static, F: FnOnce(Result<T, E>) -> Promise<R, E1>, R: 'static

Chains further computation to be executed once the promise resolves. When the promise is fulfilled or rejected, invokes func on its result.

If the returned promise is dropped before the chained computation runs, the chained computation will be cancelled.

Always returns immediately, even if the promise is already resolved. The earliest that func might be invoked is during the next turn() of the event loop.

fn then<F, R>(self, func: F) -> Promise<R, E> where F: 'static, F: FnOnce(T) -> Promise<R, E>, R: 'static

Calls then_else() with a default error handler that simply propagates all errors.

fn map_else<F, R, E1>(self, func: F) -> Promise<R, E1> where F: 'static, F: FnOnce(Result<T, E>) -> Result<R, E1>, R: 'static, E1: 'static

Like then_else() but for a func that returns a direct value rather than a promise.

fn map<F, R>(self, func: F) -> Promise<R, E> where F: 'static, F: FnOnce(T) -> Result<R, E>, R: 'static

Calls map_else() with a default error handler that simply propagates all errors.

fn map_err<E1, F>(self, func: F) -> Promise<T, E1> where F: 'static, F: FnOnce(E) -> E1

Transforms the error branch of the promise.

fn lift<E1>(self) -> Promise<T, E1> where E: Into<E1>

Maps errors into a more general type.

fn exclusive_join(self, other: Promise<T, E>) -> Promise<T, E>

Returns a new promise that resolves when either self or other resolves. The promise that doesn't resolve first is cancelled.

fn ok(value: T) -> Promise<T, E>

Creates a new promise that has already been fulfilled.

fn err(error: E) -> Promise<T, E>

Creates a new promise that has already been rejected with the given error.

fn never_done() -> Promise<T, E>

Creates a new promise that never gets fulfilled.

fn and_fulfiller() -> (Promise<T, E>, PromiseFulfiller<T, E>) where E: FulfillerDropped

Creates a new promise/fulfiller pair.

fn all<I>(promises: I) -> Promise<Vec<T>, E> where I: Iterator<Item=Promise<T, E>>

Transforms a collection of promises into a promise for a vector. If any of the promises fails, immediately cancels the remaining promises.

fn fork(self) -> ForkedPromise<T, E> where T: Clone, E: Clone

Forks the promise, so that multiple different clients can independently wait on the result.

fn attach<U>(self, value: U) -> Promise<T, E> where U: 'static

Holds onto value until the promise resolves, then drops value.

fn eagerly_evaluate(self) -> Promise<T, E>

fn wait(self, _wait_scope: &WaitScope) -> Result<T, E>

Runs the event loop until the promise is fulfilled.

The WaitScope argument ensures that wait() can only be called at the top level of a program. Waiting within event callbacks is disallowed.