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