Struct NapiThreadsafeFunction

Source
pub struct NapiThreadsafeFunction<Data, const N: usize>(/* private fields */);

Implementations§

Source§

impl<Data, const N: usize> NapiThreadsafeFunction<Data, N>

Source

pub fn env(&self) -> NapiEnv

Source

pub fn raw(&self) -> napi_threadsafe_function

Source

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.

Source

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.

Source

pub fn blocking(&self, data: Data) -> NapiResult<()>

Source

pub fn non_blocking(&self, data: Data) -> NapiResult<()>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source§

fn clone(&self) -> NapiThreadsafeFunction<Data, N>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Data: Debug, const N: usize> Debug for NapiThreadsafeFunction<Data, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Data: Copy, const N: usize> Copy for NapiThreadsafeFunction<Data, N>

Source§

impl<Data, const N: usize> Send for NapiThreadsafeFunction<Data, N>

Source§

impl<Data, const N: usize> Sync for NapiThreadsafeFunction<Data, N>

Auto Trait Implementations§

§

impl<Data, const N: usize> Freeze for NapiThreadsafeFunction<Data, N>

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.