https://github.com/spacejam/rust-futurepool
simple future pool library for predictable concurrency
https://github.com/spacejam/rust-futurepool
Last synced: 11 months ago
JSON representation
simple future pool library for predictable concurrency
- Host: GitHub
- URL: https://github.com/spacejam/rust-futurepool
- Owner: spacejam
- Created: 2015-01-20T03:05:08.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-20T06:24:33.000Z (over 11 years ago)
- Last Synced: 2025-02-11T07:23:10.929Z (over 1 year ago)
- Language: Rust
- Size: 113 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[WIP] FuturePool
============
Tiny future pool library.
```rust
extern crate futurepool;
use futurepool::FuturePool;
fn server() {
let fp = FuturePool::new(std::os::num_cpus() / 4);
...
for req in some_acceptor.iter() {
// This creates 2 tasks in the future pool
// to be executed asynchronously:
// 1. execute the handler
// 2. respond to the request when #1 is complete
// If either step fails, any on_failure calls will be
// executed sequentially.
fp.execute(|&:| -> Rep {
user_supplied_handler(req);
}).map(|&: rep: Rep| {
req.respond(rep);
}).on_failure(|&: error: Err| {
println!("failed to process OR respond: {}", error);
});
}
}
```