summaryrefslogtreecommitdiffstats
path: root/core/src/default_impl/cpupool.rs
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/default_impl/cpupool.rs')
-rw-r--r--core/src/default_impl/cpupool.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/core/src/default_impl/cpupool.rs b/core/src/default_impl/cpupool.rs
new file mode 100644
index 0000000..de02deb
--- /dev/null
+++ b/core/src/default_impl/cpupool.rs
@@ -0,0 +1,47 @@
+
+use futures::Future;
+use utils::SendBoxFuture;
+
+use futures_cpupool::{ CpuPool, Builder};
+
+use context::OffloaderComponent;
+
+/// Create a `futures_cpupool::CpuPool` with default parameters.
+///
+/// Note that this crate implements `OffloaderComponent` for `CpuPool`.
+/// (Which is a component of the context used to build/encode mails and
+/// should not be confused with header components).
+pub fn simple_cpu_pool() -> CpuPool {
+ Builder::new().create()
+}
+
+impl OffloaderComponent for CpuPool {
+ /// executes the futures `fut` "elswhere" e.g. in a cpu pool
+ 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 );
+ }
+} \ No newline at end of file