Struct eventual::Future
[−]
[src]
#[must_use = "futures are lazy and do nothing unless consumed"]pub struct Future<T: Send + 'static, E: Send + 'static> { /* fields omitted */ }
Methods
impl<T: Send + 'static, E: Send + 'static> Future<T, E>
[src]
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>,
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,
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,
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, ()>
[src]
fn spawn<F>(f: F) -> Future<T, ()> where
F: FnOnce() -> T + Send + 'static,
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>
[src]
Trait Implementations
impl<T: Send + 'static, E: Send + 'static> Async for Future<T, E>
[src]
type Value = T
type Error = E
type Cancel = Receipt<Future<T, E>>
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<T, E>, Future<T, E>>
Get the underlying value if present
fn ready<F: FnOnce(Future<T, E>) + Send + 'static>(
self,
f: F
) -> Receipt<Future<T, E>>
self,
f: F
) -> Receipt<Future<T, E>>
Invokes the given function when the Async instance is ready to be consumed. Read more
fn await(self) -> AsyncResult<T, E>
Blocks the thread until the async value is complete and returns the result. Read more
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,
F: FnOnce(AsyncResult<Self::Value, Self::Error>) + Send + 'static,
Invoke the callback with the resolved Async
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>
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. Read more
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,
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. Read more
fn or<A>(self, alt: A) -> Future<Self::Value, A::Error> where
A: Async<Value = Self::Value>,
A: Async<Value = Self::Value>,
This method returns a future whose completion value depends on the completion value of the original future. Read more
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>,
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. Read more