Skip to content

Commit

Permalink
Add more examples to README
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidd committed Oct 8, 2014
1 parent 5c01415 commit e46654a
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## [Documentation](http://www.rust-ci.org/lucidd/rust-promise/doc/promise/)

## Example
## Examples

### Basics

```rust
extern crate promise;
Expand All @@ -17,3 +19,41 @@ fn main() {
println!("end of main");
}
```

### Composing Futures

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

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

0 comments on commit e46654a

Please sign in to comment.