Struct executors::Future [] [src]

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

Methods

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

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 R: Async<Value=T, Error=E>, F: FnOnce() -> R + Send + 'static

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 U: Send + 'static, F: FnOnce(T) -> U + Send + 'static

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

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, E> Future<Option<(T, Stream<T, E>)>, E> where E: Send + 'static, T: Send + 'static

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

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

Trait Implementations

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

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<Result<T, AsyncError<E>>, Future<T, E>>

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

fn await(self) -> Result<T, AsyncError<E>>

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

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

fn fire(self)

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

fn and_then<F, U>(self, f: F) -> Future<U::Value, Self::Error> where U: Async<Error=Self::Error>, F: FnOnce(Self::Value) -> U + Send + 'static, U::Value: Send, U::Value: '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, E> Pair for Future<T, E> where T: Send + 'static, E: Send + 'static

type Tx = Complete<T, E>

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

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

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

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

fn drop(&mut self)

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

type Value = T

type Error = E

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