chore(napi): expose tokio runtime's block_on function (#1352)

This commit is contained in:
Simon Laux 2022-11-15 04:49:46 +01:00 committed by GitHub
parent d48d106588
commit b0c248ad7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,6 +59,16 @@ where
RT.0.spawn(fut); RT.0.spawn(fut);
} }
/// Runs a future to completion
/// This is blocking, meaning that it pauses other execution until the future is complete,
/// only use it when it is absolutely necessary, in other places use async functions instead.
pub fn block_on<F>(fut: F) -> F::Output
where
F: 'static + Send + Future<Output = ()>,
{
RT.0.block_on(fut)
}
// This function's signature must be kept in sync with the one in lib.rs, otherwise napi // This function's signature must be kept in sync with the one in lib.rs, otherwise napi
// will fail to compile with the `tokio_rt` feature. // will fail to compile with the `tokio_rt` feature.