2019-09-03 09:16:29 +00:00
|
|
|
//! Helpers for quirks of the current tokio runtime.
|
|
|
|
|
|
|
|
use std::future::Future;
|
|
|
|
|
|
|
|
pub fn main<F, T>(fut: F) -> T
|
|
|
|
where
|
|
|
|
F: Future<Output = T> + Send + 'static,
|
|
|
|
T: std::fmt::Debug + Send + 'static,
|
|
|
|
{
|
2019-12-12 14:27:07 +00:00
|
|
|
let mut rt = tokio::runtime::Runtime::new().unwrap();
|
2019-09-03 09:16:29 +00:00
|
|
|
rt.block_on(async {
|
|
|
|
let (tx, rx) = tokio::sync::oneshot::channel();
|
|
|
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
tx.send(fut.await).unwrap()
|
|
|
|
});
|
|
|
|
|
|
|
|
rx.await.unwrap()
|
|
|
|
})
|
|
|
|
}
|