-
Notifications
You must be signed in to change notification settings - Fork 0
/
into.rs
43 lines (36 loc) · 790 Bytes
/
into.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
extern crate poolite;
use poolite::Pool;
use std::io;
/// `cargo run --example into`
fn main() {
into_inner();
println!(); // newline
println!("{:?}", into_error());
}
fn into_inner() {
let pool = match Pool::new() {
Ok(p) => p,
Err(e) => e.into_inner(),
};
for i in 0..38 {
pool.push(move || test(i));
}
pool.join(); //wait for the pool
}
fn into_error() -> io::Result<()> {
let pool = Pool::new().map_err(|e| e.into_error())?;
for i in 0..38 {
pool.push(move || test(i));
}
pool.join(); //wait for the pool
Ok(())
}
fn test(msg: i32) {
println!("key: {}\tvalue: {}", msg, fib(msg));
}
fn fib(msg: i32) -> i32 {
match msg {
0...2 => 1,
x => fib(x - 1) + fib(x - 2),
}
}