#future #value #future-promise

nightly promise

A simple future/promise library for rust

4 releases

Uses old Rust 2015

0.0.4 Jan 13, 2015
0.0.3 Dec 16, 2014
0.0.2 Nov 22, 2014
0.0.1 Nov 22, 2014

#928 in Asynchronous

MIT license

14KB
325 lines

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");
}

No runtime deps