fix(napi): remove useless aquire while creating ThreadsafeFunction (#1442)

This commit is contained in:
LongYinan 2023-01-18 11:20:47 +08:00 committed by GitHub
parent 3db49adcdc
commit 6739ddda20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 7 deletions

View file

@ -246,8 +246,6 @@ impl<T: 'static, ES: ErrorStrategy::T> ThreadsafeFunction<T, ES> {
)
})?;
check_status!(unsafe { sys::napi_acquire_threadsafe_function(raw_tsfn) })?;
Ok(ThreadsafeFunction {
handle: Arc::new(ThreadsafeFunctionHandle {
raw: raw_tsfn,

View file

@ -8,14 +8,12 @@ use napi::{
#[napi]
pub fn call_threadsafe_function(callback: JsFunction) -> Result<()> {
let tsfn: ThreadsafeFunction<u32, ErrorStrategy::CalleeHandled> = callback
.create_threadsafe_function(0, |ctx| {
ctx.env.create_uint32(ctx.value + 1).map(|v| vec![v])
})?;
let tsfn: ThreadsafeFunction<u32, ErrorStrategy::CalleeHandled> =
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(())