ThreadsafeFn
Thread-safe wrapper around a JS function. T is the per-call payload type. Built via Callback.threadsafe(env, name, T) or Callback.threadsafeWithOptions.
threadsafe keeps the compatible unbounded Node-API queue. Use ThreadsafeOptions when .non_blocking must provide backpressure:
max_queue_size = 0 means unbounded; a positive value creates a bounded queue.
For the conceptual model and lifecycle rules, see Threadsafe functions.
T semantics
Methods
call(value, mode)
mode is napi.ThreadsafeFn(T).Mode:
.blockingwaits if a bounded queue is full..non_blockingreturnserror.QueueFullif a bounded queue is full.
An unbounded queue never reports QueueFull; choose a positive max_queue_size when producer backpressure is required.
For T = void, the call signature is try tsfn.call({}, mode).
call deep-copies slice-backed data and ordinary fixed-array pointers in supported structural payloads before enqueueing. Conversion failures and exceptions thrown by the JavaScript callback are forwarded exactly once through Node.js's uncaughtException path.
Payloads must be finite native values that the bridge can snapshot completely. Call-scoped handles (Env, Val, Callback, CallInfo, including nested occurrences) are compile errors because they cannot outlive their originating callback or cross a thread. Borrowed raw, many-item/sentinel, C, specially qualified, and recursively self-referential pointers are compile errors too; use a value, slice, fixed array, or stable ID instead.