Struct nodex_api::tsfn::NapiThreadsafeFunction
source · [−]pub struct NapiThreadsafeFunction<Data, const N: usize>(_, _, _);
Implementations
sourceimpl<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
sourceimpl<Data: Clone, const N: usize> Clone for NapiThreadsafeFunction<Data, N>
impl<Data: Clone, const N: usize> Clone for NapiThreadsafeFunction<Data, N>
sourcefn clone(&self) -> NapiThreadsafeFunction<Data, N>
fn clone(&self) -> NapiThreadsafeFunction<Data, N>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<Data: Debug, const N: usize> Debug for NapiThreadsafeFunction<Data, N>
impl<Data: Debug, const N: usize> Debug for NapiThreadsafeFunction<Data, N>
impl<Data: Copy, const N: usize> Copy for NapiThreadsafeFunction<Data, N>
impl<Data, const N: usize> Send for NapiThreadsafeFunction<Data, N>
impl<Data, const N: usize> Sync for NapiThreadsafeFunction<Data, N>
Auto Trait Implementations
impl<Data, const N: usize> RefUnwindSafe for NapiThreadsafeFunction<Data, N> where
Data: RefUnwindSafe,
impl<Data, const N: usize> Unpin for NapiThreadsafeFunction<Data, N> where
Data: Unpin,
impl<Data, const N: usize> UnwindSafe for NapiThreadsafeFunction<Data, N> where
Data: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more