promise 0.0.4

A simple future/promise library for rust
docs.rs failed to build promise-0.0.4
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

rust-promise Build Status

Documentation

Examples

Basics

extern crate promise;

use promise::Future;

fn main() {
    let f = Future::from_fn(proc() "hello world!");
    f.on_success(proc(value){
        println!("{}", value)
    });
    println!("end of main");
}

Composing Futures

extern crate promise;

use promise::Future;
use std::time::duration::Duration;

fn main() {
    let hello = Future::delay(proc() "hello", Duration::seconds(3));
    let world = Future::from_fn(proc() "world");
    let hw = Future::all(vec![hello, world]);
    hw.map(proc(f) format!("{} {}!", f[0], f[1]))
      .on_success(proc(value){
        println!("{}", value)
    });
    println!("end of main");
}
extern crate promise;

use promise::Future;
use std::time::duration::Duration;


fn main() {
    let timeout = Future::delay(proc() Err("timeout"), Duration::seconds(2));
    let f = Future::delay(proc() Ok("hello world!"), Duration::seconds(3));
    let hw = Future::first_of(vec![f, timeout]);
    hw.on_success(proc(value){
        println!("{}", value)
    });
    println!("end of main");
}