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
44
45
46
47
use futures::Future;
use utils::SendBoxFuture;
use futures_cpupool::{ CpuPool, Builder};
use context::OffloaderComponent;
pub fn simple_cpu_pool() -> CpuPool {
Builder::new().create()
}
impl OffloaderComponent for CpuPool {
fn offload<F>(&self, fut: F) -> SendBoxFuture<F::Item, F::Error>
where F: Future + Send + 'static,
F::Item: Send+'static,
F::Error: Send+'static
{
Box::new( self.spawn( fut ) )
}
}
#[cfg(test)]
mod test {
use futures::future;
use futures_cpupool::Builder;
use super::*;
#[test]
fn check_if_it_works() {
let pool = Builder::new().create();
_check_if_it_works( pool )
}
fn _check_if_it_works<R: OffloaderComponent>(r: R) {
let res = r.offload(future::lazy(||-> Result<u32, ()> { Ok(33u32) } )).wait();
let val = assert_ok!( res );
assert_eq!( 33u32, val );
}
}