blocking_future/
lib.rs

1pub struct BlockingFuture<F: FnOnce() -> T, T> {
2    f: Option<F>,
3}
4
5impl<F: FnOnce() -> T, T> BlockingFuture<F, T> {
6    pub fn new(f: F) -> Self {
7        Self { f: Some(f) }
8    }
9}
10
11impl<F: FnOnce() -> T, T> futures::Future for BlockingFuture<F, T> {
12    type Item = T;
13    type Error = tokio_threadpool::BlockingError;
14    fn poll(&mut self) -> futures::Poll<Self::Item, Self::Error> {
15        tokio_threadpool::blocking(|| self.f.take().expect("closure already used")())
16    }
17}