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

type Value: Send + 'static

type Error: Send + 'static

type Cancel: Cancel<Self>

Required Methods

fn is_ready(&self) -> bool

Returns true if expect will succeed.

fn is_err(&self) -> bool

Returns true if the async value is ready and has failed

fn poll(self) -> Result<AsyncResult<Self::Value, Self::Error>, Self>

Get the underlying value if present

fn ready<F>(self, f: F) -> Self::Cancel where F: FnOnce(Self) + Send + 'static

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

Provided Methods

fn expect(self) -> AsyncResult<Self::Value, Self::Error>

Get the underlying value if present, panic otherwise

fn receive<F>(self, f: F) where F: FnOnce(AsyncResult<Self::Value, Self::Error>) + Send + 'static

Invoke the callback with the resolved Async result.

fn await(self) -> AsyncResult<Self::Value, Self::Error>

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

fn fire(self)

Trigger the computation without waiting for the result

fn and<U: Async<Error=Self::Error>>(self, next: U) -> Future<U::Value, Self::Error>

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.

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

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();

fn or<A>(self, alt: A) -> Future<Self::Value, A::Error> where A: Async<Value=Self::Value>

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.

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>

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