Refactor async runtime usage with AsyncHandler wrapper

This commit is contained in:
Tunglies
2025-04-11 17:47:08 +08:00
parent b6a6f5f434
commit 51ef1329be
7 changed files with 55 additions and 38 deletions

View File

@@ -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())
}
}