我们可以使用napi_unref_threadsafe_function来释放引用。 constnapi_unref_threadsafe_function=require('napi_unref_threadsafe_function');napi_unref_threadsafe_function(ref); 1. 2. 3. 至此,我们已经完成了实现“napi_ref_threadsafe_fun
tsfn: Add wrappers for Ref and Unref#561: This adds wrappers fornapi_ref_threadsafe_function/napi_unref_threadsafe_functiondirectly tsfn: Implement copy constructor#546 operator napi_threadsafe_function napi_unref_threadsafe_function KevinEady commentedon Oct 22, 2019 ...
check_status!(unsafe { sys::napi_unref_threadsafe_function(env.0, self.raw_tsfn) }) }pub fn aborted(&self) -> bool { self.aborted.load(Ordering::Acquire) self.aborted.load(Ordering::Relaxed) }pub fn abort(self) -> Result<()> { @@ -280,18 +280,14 @@ impl<T: 'static> Thre...
napi_create_threadsafe_function(env, nullptr, nullptr, resourceName, 0, 1, nullptr, nullptr, nullptr, ThreadSafeCallback, &defaultFunc_); } void NativeEngine::DestoryDefaultFunction(void) { std::unique_lock<std::shared_mutex> writeLock(eventMutex_); ...
FunctionReference _callback; std::string _error; bool _suppress_destruct; }; #if (NAPI_VERSION > 3 && !defined(__wasm32__)) class ThreadSafeFunction { public: // This API may only be called from the main thread. template <typename ResourceString> static ThreadSafeFunction New...
DECLARE_NAPI_PROPERTY("StopThread", StopThread), DECLARE_NAPI_PROPERTY("Unref", Unref), DECLARE_NAPI_PROPERTY("Release", Release),11 changes: 11 additions & 0 deletions 11 test/node-api/test_threadsafe_function/test.js Original file line numberDiff line numberDiff line change ...
env->Unref(); } ~ThreadSafeFunction() { ReleaseResources(); }// These methods can be called from any thread.napi_status Push(void* data, napi_threadsafe_function_call_mode mode) { node::Mutex::ScopedLock lock(this->mutex); { node::Mutex::ScopedLock lock(this->mutex);while...
"Create Custom GC ThreadsafeFunction in napi_register_module_v1 failed" ); check_status_or_throw!( env, unsafe { sys::napi_unref_threadsafe_function(env, custom_gc_tsfn) }, "Unref Custom GC ThreadsafeFunction in napi_register_module_v1 failed" ); CUSTOM_GC_TSFN.store(custom_gc_tsfn,...
voidexample_async_return_value(constCallbackInfo& info) {autocallback = std::make_shared<ThreadSafeCallback>(info[0].As<Function>());std::thread([callback] {try{intresult =0;while(true) {//Do some work...try{ result +=1;if(result >20)throwstd::runtime_error("Failure during async...
(napi_env env, napi_status status, void* asyncworker); napi_env _env; napi_async_work _work; ObjectReference _receiver; FunctionReference _callback; std::string _error; bool _suppress_destruct; }; #if (NAPI_VERSION > 3 && !defined(__wasm32__)) class ThreadSafeFunction { public: //...