pub struct NapiThreadsafeFunction<Data, const N: usize>(/* private fields */);
Implementations§
Source§impl<Data, const N: usize> NapiThreadsafeFunction<Data, N>
impl<Data, const N: usize> NapiThreadsafeFunction<Data, N>
pub fn env(&self) -> NapiEnv
pub fn raw(&self) -> napi_threadsafe_function
Sourcepub fn new<R>(
env: NapiEnv,
name: impl AsRef<str>,
func: Function<R>,
finalizer: impl FnOnce(NapiEnv) -> NapiResult<()>,
callback: impl FnMut(Function<R>, Data) -> NapiResult<()>,
) -> NapiResult<NapiThreadsafeFunction<Data, N>>where
R: NapiValueT,
pub fn new<R>(
env: NapiEnv,
name: impl AsRef<str>,
func: Function<R>,
finalizer: impl FnOnce(NapiEnv) -> NapiResult<()>,
callback: impl FnMut(Function<R>, Data) -> NapiResult<()>,
) -> NapiResult<NapiThreadsafeFunction<Data, N>>where
R: NapiValueT,
Create a napi_threadsafe_function
R: the returned value of function. N: the maximum size of the queue, 0 for no limit.
Sourcepub fn call(
&self,
data: Data,
mode: NapiThreadsafeFunctionCallMode,
) -> NapiResult<()>
pub fn call( &self, data: Data, mode: NapiThreadsafeFunctionCallMode, ) -> NapiResult<()>
This API should not be called with napi_tsfn_blocking from a JavaScript thread, because, if the queue is full, it may cause the JavaScript thread to deadlock.
This API will return napi_closing if napi_release_threadsafe_function() was called with abort set to napi_tsfn_abort from any thread. The value is only added to the queue if the API returns napi_ok.
This API may be called from any thread which makes use of func.
pub fn blocking(&self, data: Data) -> NapiResult<()>
pub fn non_blocking(&self, data: Data) -> NapiResult<()>
Sourcepub fn acquire(&self) -> NapiResult<()>
pub fn acquire(&self) -> NapiResult<()>
A thread should call this API before passing func to any other thread-safe function APIs to indicate that it will be making use of func. This prevents func from being destroyed when all other threads have stopped making use of it.
This API may be called from any thread which will start making use of func.
Sourcepub fn release(self) -> NapiResult<()>
pub fn release(self) -> NapiResult<()>
A thread should call this API when it stops making use of func. Passing func to any thread-safe APIs after having called this API has undefined results, as func may have been destroyed.
This API may be called from any thread which will stop making use of func.
Sourcepub fn abort(self) -> NapiResult<()>
pub fn abort(self) -> NapiResult<()>
A thread should call this API when it stops making use of func. Passing func to any thread-safe APIs after having called this API has undefined results, as func may have been destroyed.
This API may be called from any thread which will stop making use of func.
Sourcepub fn refer(&self) -> NapiResult<()>
pub fn refer(&self) -> NapiResult<()>
This API is used to indicate that the event loop running on the main thread should not exit until func has been destroyed. Similar to uv_ref it is also idempotent.
Neither does napi_unref_threadsafe_function mark the thread-safe functions as able to be destroyed nor does napi_ref_threadsafe_function prevent it from being destroyed. napi_acquire_threadsafe_function and napi_release_threadsafe_function are available for that purpose.
This API may only be called from the main thread.
Sourcepub fn unref(&self) -> NapiResult<()>
pub fn unref(&self) -> NapiResult<()>
This API is used to indicate that the event loop running on the main thread may exit before func is destroyed. Similar to uv_unref it is also idempotent.
This API may only be called from the main thread.
Trait Implementations§
Source§impl<Data: Clone, const N: usize> Clone for NapiThreadsafeFunction<Data, N>
impl<Data: Clone, const N: usize> Clone for NapiThreadsafeFunction<Data, N>
Source§fn clone(&self) -> NapiThreadsafeFunction<Data, N>
fn clone(&self) -> NapiThreadsafeFunction<Data, N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more