@@ -48,7 +48,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
48
48
use std:: thread;
49
49
50
50
use crossbeam:: sync:: MsQueue ;
51
- use futures:: { Future , oneshot, Oneshot , Complete , Poll } ;
51
+ use futures:: { IntoFuture , Future , oneshot, Oneshot , Complete , Poll } ;
52
52
use futures:: task:: { self , Run , Executor } ;
53
53
54
54
/// A thread pool intended to run CPU intensive work.
@@ -165,6 +165,25 @@ impl CpuPool {
165
165
task:: spawn ( sender) . execute ( self . inner . clone ( ) ) ;
166
166
CpuFuture { inner : rx }
167
167
}
168
+
169
+ /// Spawns a closure on this thread pool.
170
+ ///
171
+ /// This function is a convenience wrapper around the `spawn` function above
172
+ /// for running a closure wrapped in `futures::lazy`. It will spawn the
173
+ /// function `f` provided onto the thread pool, and continue to run the
174
+ /// future returned by `f` on the thread pool as well.
175
+ ///
176
+ /// The returned future will be a handle to the result produced by the
177
+ /// future that `f` returns.
178
+ pub fn spawn_fn < F , R > ( & self , f : F ) -> CpuFuture < R :: Item , R :: Error >
179
+ where F : FnOnce ( ) -> R + Send + ' static ,
180
+ R : IntoFuture + ' static ,
181
+ R :: Future : Send + ' static ,
182
+ R :: Item : Send + ' static ,
183
+ R :: Error : Send + ' static ,
184
+ {
185
+ self . spawn ( futures:: lazy ( f) )
186
+ }
168
187
}
169
188
170
189
fn work ( inner : & Inner ) {
0 commit comments