promising_future/
spawner.rs1use std::thread;
2
3#[cfg(feature = "threadpool")]
4use threadpool;
5
6pub trait Spawner {
8 fn spawn<F>(&self, f: F) where F: FnOnce() + Send + 'static;
10}
11
12pub struct ThreadSpawner;
14
15impl Spawner for ThreadSpawner {
16 fn spawn<F>(&self, f: F)
17 where F: FnOnce() + Send + 'static
18 {
19 let _ = thread::spawn(f);
20 }
21}
22
23#[cfg(feature = "threadpool")]
24impl Spawner for threadpool::ThreadPool {
25 fn spawn<F>(&self, f: F)
26 where F: FnOnce() + Send + 'static
27 {
28 self.execute(f)
29 }
30}