fix(napi): remove useless aquire while creating ThreadsafeFunction (#1442)
This commit is contained in:
parent
3db49adcdc
commit
6739ddda20
2 changed files with 3 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -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(())
|
||||
|
|
Loading…
Reference in a new issue