diff --git a/crates/napi/src/tokio_runtime.rs b/crates/napi/src/tokio_runtime.rs index ceb8507e8a..932d387df1 100644 --- a/crates/napi/src/tokio_runtime.rs +++ b/crates/napi/src/tokio_runtime.rs @@ -52,11 +52,15 @@ pub unsafe extern "C" fn shutdown_tokio_rt(arg: *mut c_void) { } } -pub fn spawn(fut: F) +/// Spawns a future onto the Tokio runtime. +/// +/// Depending on where you use it, you should await or abort the future in your drop function. +/// To avoid undefined behavior and memory corruptions. +pub fn spawn(fut: F) -> tokio::task::JoinHandle where F: 'static + Send + Future, { - RT.0.spawn(fut); + RT.0.spawn(fut) } /// Runs a future to completion