diff --git a/crates/napi/src/tokio_runtime.rs b/crates/napi/src/tokio_runtime.rs index cf828a31..f7728b39 100644 --- a/crates/napi/src/tokio_runtime.rs +++ b/crates/napi/src/tokio_runtime.rs @@ -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(func: F) -> tokio::task::JoinHandle +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.