Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucidd/rust-promise
A future/promise library for rust
https://github.com/lucidd/rust-promise
Last synced: 4 days ago
JSON representation
A future/promise library for rust
- Host: GitHub
- URL: https://github.com/lucidd/rust-promise
- Owner: lucidd
- Created: 2014-09-22T00:51:31.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-13T05:34:56.000Z (almost 10 years ago)
- Last Synced: 2024-09-15T09:01:56.733Z (about 2 months ago)
- Language: Rust
- Homepage:
- Size: 292 KB
- Stars: 20
- Watchers: 6
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rust-promise [![Build Status](https://travis-ci.org/lucidd/rust-promise.svg?branch=master)](https://travis-ci.org/lucidd/rust-promise)
## [Documentation](http://www.rust-ci.org/lucidd/rust-promise/doc/promise/)
## Examples
### Basics
```rust
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
```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");
}
```