Struct tangle::Future [] [src]

pub struct Future<T, E = ()> { /* fields omitted */ }

A value that will be resolved sometime into the future, asynchronously. Futures use an internal threadpool to handle asynchronous tasks.

Methods

impl<T, E = ()> Future<T, E> where
    T: Send + 'static,
    E: Send + 'static, 
[src]

use tangle::{Future, Async};

Future::new(|| if true { Async::Ok(123) } else { Async::Err("Foobar") });

Create a new future from the receiving end of a native channel.

use tangle::{Future, Async};
use std::thread;
use std::sync::mpsc::channel;

let (tx, rx) = channel();
Future::<u32>::from_channel(rx).and_then(|v| {
    assert_eq!(v, 1235);
    Async::Ok(())
});
tx.send(1235);

use tangle::{Future, Async};

let f: Future<usize> = Future::unit(1);

let purchase: Future<String> = f.and_then(|num| Async::Ok(num.to_string()));

match purchase.recv() {
    Ok(val) => assert_eq!(val, "1".to_string()),
    _ => panic!("unexpected")
}

use tangle::{Future, Async};

let f: Future<usize> = Future::unit(1);

let purchase: Future<String> = f.map(|num| num.to_string());

match purchase.recv() {
    Ok(val) => assert_eq!(val, "1".to_string()),
    _ => panic!("unexpected")
}

Wrap a value into a Future that completes right away.

Usage

use tangle::Future;

let _: Future<usize> = Future::unit(5);

use tangle::Future;

let _: Future<usize, &str> = Future::err("foobar");

Trait Implementations

impl<T: Debug, E: Debug> Debug for Future<T, E>
[src]

Formats the value using the given formatter.