Struct gj::Promise [] [src]

pub struct Promise<T, E> where
    T: 'static,
    E: 'static, 
{ /* fields omitted */ }

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


impl<T, E> Promise<T, E>

Creates a new promise that has already been fulfilled with the given value.

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

Creates a new promise that never resolves.

Creates a new promise/fulfiller pair.

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.

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

Like then_else() but for a func that returns a direct value rather than a promise. As an optimization, execution of func is delayed until its result is known to be needed. The expectation here is that func is just doing some transformation on the results, not scheduling any other actions, and therefore the system does not need to be proactive about evaluating it. This way, a chain of trivial map() transformations can be executed all at once without repeated rescheduling through the event loop. Use the eagerly_evaluate() method to suppress this behavior.

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

Transforms the error branch of the promise.

Maps errors into a more general type.

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

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

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

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

Forces eager evaluation of this promise. Use this if you are going to hold on to the promise for a while without consuming the result, but you want to make sure that the system actually processes it.

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.