2019-05-14 10:27:36 -07:00
|
|
|
use tokio_threadpool;
|
2018-11-16 14:50:06 -08:00
|
|
|
|
|
|
|
|
use self::tokio_threadpool::Builder;
|
2019-07-11 11:05:49 -05:00
|
|
|
use std::future::Future;
|
2018-11-16 14:50:06 -08:00
|
|
|
use std::io;
|
2019-07-11 11:05:49 -05:00
|
|
|
use std::sync::mpsc;
|
2018-11-16 14:50:06 -08:00
|
|
|
|
|
|
|
|
pub fn run<F>(f: F)
|
|
|
|
|
where
|
2019-07-11 11:05:49 -05:00
|
|
|
F: Future<Output = io::Result<()>> + Send + 'static,
|
2018-11-16 14:50:06 -08:00
|
|
|
{
|
|
|
|
|
let pool = Builder::new().pool_size(1).build();
|
2019-07-11 11:05:49 -05:00
|
|
|
let (tx, rx) = mpsc::channel();
|
|
|
|
|
pool.spawn(async move {
|
|
|
|
|
f.await.unwrap();
|
|
|
|
|
tx.send(()).unwrap();
|
|
|
|
|
});
|
|
|
|
|
rx.recv().unwrap()
|
2018-11-16 14:50:06 -08:00
|
|
|
}
|