fix(napi): return the join handle when spawning a tokio task. (#1351)
we need this to be able to safely drop an struct, that makes use of an async task. the drop function needs to be able to call `.abort()` on the join handle to avoid memory corruption and undefined bahviour.
This commit is contained in:
parent
b0c248ad7e
commit
035def0600
1 changed files with 6 additions and 2 deletions
|
@ -52,11 +52,15 @@ pub unsafe extern "C" fn shutdown_tokio_rt(arg: *mut c_void) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn spawn<F>(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<F>(fut: F) -> tokio::task::JoinHandle<F::Output>
|
||||
where
|
||||
F: 'static + Send + Future<Output = ()>,
|
||||
{
|
||||
RT.0.spawn(fut);
|
||||
RT.0.spawn(fut)
|
||||
}
|
||||
|
||||
/// Runs a future to completion
|
||||
|
|
Loading…
Reference in a new issue