Refactor async runtime usage with AsyncHandler wrapper
This commit is contained in:
@@ -11,4 +11,20 @@ impl AsyncHandler {
|
||||
{
|
||||
async_runtime::spawn(f())
|
||||
}
|
||||
|
||||
pub fn spawn_blocking<F, R>(f: F) -> JoinHandle<R>
|
||||
where
|
||||
F: FnOnce() -> R + Send + 'static,
|
||||
R: Send + 'static,
|
||||
{
|
||||
async_runtime::spawn_blocking(f)
|
||||
}
|
||||
|
||||
pub fn block_on<F, Fut, R>(f: F) -> R
|
||||
where
|
||||
F: FnOnce() -> Fut,
|
||||
Fut: Future<Output = R>,
|
||||
{
|
||||
async_runtime::block_on(f())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user