tools: add tokio::main() replacement
to deal with block_on() not allowing blocking() Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
20
src/tools/runtime.rs
Normal file
20
src/tools/runtime.rs
Normal file
@ -0,0 +1,20 @@
|
||||
//! 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,
|
||||
{
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
rt.block_on(async {
|
||||
let (tx, rx) = tokio::sync::oneshot::channel();
|
||||
|
||||
tokio::spawn(async move {
|
||||
tx.send(fut.await).unwrap()
|
||||
});
|
||||
|
||||
rx.await.unwrap()
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user