Trait eventual::Async [] [src]

pub trait Async: Send + 'static + Sized {
    type Value: Send + 'static;
    type Error: Send + 'static;
    type Cancel: Cancel<Self>;
    fn is_ready(&self) -> bool;
    fn is_err(&self) -> bool;
    fn poll(self) -> Result<AsyncResult<Self::Value, Self::Error>, Self>;
    fn ready<F>(self, f: F) -> Self::Cancel
    where
        F: FnOnce(Self) + Send + 'static
; fn expect(self) -> AsyncResult<Self::Value, Self::Error> { ... } fn receive<F>(self, f: F)
    where
        F: FnOnce(AsyncResult<Self::Value, Self::Error>) + Send + 'static
, { ... } fn await(self) -> AsyncResult<Self::Value, Self::Error> { ... } fn fire(self) { ... } fn and<U: Async<Error = Self::Error>>(
        self,
        next: U
    ) -> Future<U::Value, Self::Error> { ... } fn and_then<F, U: Async<Error = Self::Error>>(
        self,
        f: F
    ) -> Future<U::Value, Self::Error>
    where
        F: FnOnce(Self::Value) -> U + Send + 'static,
        U::Value: Send + 'static
, { ... } fn or<A>(self, alt: A) -> Future<Self::Value, A::Error>
    where
        A: Async<Value = Self::Value>
, { ... } fn or_else<F, A>(self, f: F) -> Future<Self::Value, A::Error>
    where
        F: FnOnce(Self::Error) -> A + Send + 'static,
        A: Async<Value = Self::Value>
, { ... } }

A value representing an asynchronous computation

Associated Types

Required Methods

Returns true if expect will succeed.

Returns true if the async value is ready and has failed

Get the underlying value if present

Invokes the given function when the Async instance is ready to be consumed.

Provided Methods

Get the underlying value if present, panic otherwise

Invoke the callback with the resolved Async result.

Blocks the thread until the async value is complete and returns the result.

Trigger the computation without waiting for the result

This method returns a future whose completion value depends on the completion value of the original future.

If the original future completes with an error, the future returned by this method completes with that error.

If the original future completes successfully, the future returned by this method completes with the completion value of next.

This method returns a future whose completion value depends on the completion value of the original future.

If the original future completes with an error, the future returned by this method completes with that error.

If the original future completes successfully, the callback to this method is called with the value, and the callback returns a new future. The future returned by this method then completes with the completion value of that returned future.

use eventual::*;

let f = Future::of(1337);

f.and_then(|v| {
    assert_eq!(v, 1337);
    Ok(1007)
}).and_then(|v| {
    assert_eq!(v, 1007)
}).await();

let e = Future::<(), &'static str>::error("failed");

e.and_then(|v| {
    panic!("unreachable");
    Ok(())
}).await();

This method returns a future whose completion value depends on the completion value of the original future.

If the original future completes successfully, the future returned by this method will complete with that value.

If the original future completes with an error, the future returned by this method will complete with the completion value of the alt future passed in. That can be either a success or error.

This method returns a future whose completion value depends on the completion value of the original future.

If the original future completes successfully, the future returned by this method will complete with that value.

If the original future completes with an error, this method will invoke the callback passed to the method, which should return a future. The future returned by this method will complete with the completion value of that future. That can be either a success or error.

Implementors