Struct eventual::Future [] [src]

#[must_use = "futures are lazy and do nothing unless consumed"]
pub struct Future<T: Send + 'static, E: Send + 'static> {
    // some fields omitted
}

Methods

impl<T: Send + 'static, E: Send + 'static> Future<T, E>

fn pair() -> (Complete<T, E>, Future<T, E>)

fn of(val: T) -> Future<T, E>

Returns a future that will immediately succeed with the supplied value.

use eventual::*;

Future::<i32, ()>::of(1).and_then(|val| {
    assert!(val == 1);
    Ok(val + 1)
});

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

Returns a future that will immediately fail with the supplied error.

use eventual::*;

Future::error("hi").or_else(|err| {
    assert!(err == "hi");
    Ok::<(), ()>(())
}).fire();

fn lazy<F, R>(f: F) -> Future<T, E> where F: FnOnce() -> R + Send + 'static, R: Async<Value=T, Error=E>

Returns a future that won't kick off its async action until a consumer registers interest.

use eventual::*;

let post = Future::lazy(|| {
    // Imagine a call to an HTTP lib, like so:
    // http::get("/posts/1")
    Ok("HTTP response")
});

// the HTTP request has not happened yet

// later...

post.and_then(|p| {
    println!("{:?}", p);
});
// the HTTP request has now happened

fn map<F, U>(self, f: F) -> Future<U, E> where F: FnOnce(T) -> U + Send + 'static, U: Send + 'static

fn map_err<F, U>(self, f: F) -> Future<T, U> where F: FnOnce(E) -> U + Send + 'static, U: Send + 'static

Returns a new future with an identical value as the original. If the original future fails, apply the given function on the error and use the result as the error of the new future.

impl<T: Send + 'static> Future<T, ()>

fn spawn<F>(f: F) -> Future<T, ()> where F: FnOnce() -> T + Send + 'static

Returns a Future representing the completion of the given closure. The closure will be executed on a newly spawned thread.

use eventual::*;

let future = Future::spawn(|| {
    // Represents an expensive computation
    (0..100).fold(0, |v, i| v + 1)
});

assert_eq!(100, future.await().unwrap());

impl<T: Send + 'static, E: Send + 'static> Future<Option<(T, Stream<T, E>)>, E>

fn to_stream(self) -> Stream<T, E>

An adapter that converts any future into a one-value stream

Trait Implementations

impl<T: Send + 'static, E: Send + 'static> Async for Future<T, E>

type Value = T

type Error = E

type Cancel = Receipt<Future<T, E>>

fn is_ready(&self) -> bool

fn is_err(&self) -> bool

fn poll(self) -> Result<AsyncResult<T, E>, Future<T, E>>

fn ready<F: FnOnce(Future<T, E>) + Send + 'static>(self, f: F) -> Receipt<Future<T, E>>

fn await(self) -> AsyncResult<T, E>

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 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>

impl<T: Send + 'static, E: Send + 'static> Pair for Future<T, E>

type Tx = Complete<T, E>

fn pair() -> (Complete<T, E>, Future<T, E>)

impl<T: Send + 'static, E: Send + 'static> Debug for Future<T, E>

fn fmt(&self, fmt: &mut Formatter) -> Result

impl<T: Send, E: Send> Drop for Future<T, E>

fn drop(&mut self)

impl<T: Send + 'static, E: Send + 'static> Source for Future<T, E>

type Value = T

type Error = E

fn send_all<E2: Send + 'static>(self, sender: Sender<T, E2>) -> Future<Sender<T, E2>, (E, Sender<T, E2>)>