chore(napi): expose spawn_blocking on tokio runtime (#1912)

This commit is contained in:
LongYinan 2024-01-24 17:15:36 +08:00 committed by GitHub
parent b4345d1375
commit 38568c2693
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -72,6 +72,15 @@ where
RT.read().unwrap().as_ref().unwrap().block_on(fut)
}
/// spawn_blocking on the current Tokio runtime.
pub fn spawn_blocking<F, R>(func: F) -> tokio::task::JoinHandle<R>
where
F: FnOnce() -> R + Send + 'static,
R: Send + 'static,
{
RT.read().unwrap().as_ref().unwrap().spawn_blocking(func)
}
// 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.