JSCallback wraps TypeScript functions so they can be used as C function pointers.
Basic Usage
Closure Capture
Thread Safety
Setthreadsafe: true for callbacks that may be invoked from a different thread:
Thread-Safe C Function Pointers
Whenthreadsafe: true, cb.ptr returns a real C function pointer (trampoline address) that can be passed directly to native C code:
napi_create_threadsafe_function creates a TSFN, while 16 pre-compiled native trampoline functions are allocated — one per callback slot. cb.ptr returns the trampoline address via getCallbackPtr. When native C code calls this address, TrampolineDispatcher synchronously invokes the TypeScript callback and returns the result.
Cleanup
Always callclose() to release resources: