From 6739ddda200dbd09bbd2728a6ca47b7152b735ec Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 18 Jan 2023 11:20:47 +0800 Subject: [PATCH] fix(napi): remove useless aquire while creating ThreadsafeFunction (#1442) --- crates/napi/src/threadsafe_function.rs | 2 -- examples/napi/src/threadsafe_function.rs | 8 +++----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/crates/napi/src/threadsafe_function.rs b/crates/napi/src/threadsafe_function.rs index 369b69a0..a6e791b8 100644 --- a/crates/napi/src/threadsafe_function.rs +++ b/crates/napi/src/threadsafe_function.rs @@ -246,8 +246,6 @@ impl ThreadsafeFunction { ) })?; - check_status!(unsafe { sys::napi_acquire_threadsafe_function(raw_tsfn) })?; - Ok(ThreadsafeFunction { handle: Arc::new(ThreadsafeFunctionHandle { raw: raw_tsfn, diff --git a/examples/napi/src/threadsafe_function.rs b/examples/napi/src/threadsafe_function.rs index 546e870e..fc762e88 100644 --- a/examples/napi/src/threadsafe_function.rs +++ b/examples/napi/src/threadsafe_function.rs @@ -8,14 +8,12 @@ use napi::{ #[napi] pub fn call_threadsafe_function(callback: JsFunction) -> Result<()> { - let tsfn: ThreadsafeFunction = callback - .create_threadsafe_function(0, |ctx| { - ctx.env.create_uint32(ctx.value + 1).map(|v| vec![v]) - })?; + let tsfn: ThreadsafeFunction = + callback.create_threadsafe_function(0, |ctx| Ok(vec![ctx.value + 1]))?; for n in 0..100 { let tsfn = tsfn.clone(); thread::spawn(move || { - tsfn.call(Ok(n), ThreadsafeFunctionCallMode::Blocking); + tsfn.call(Ok(n), ThreadsafeFunctionCallMode::NonBlocking); }); } Ok(())