Callbacks
Accept a JS function as a parameter using napi.Callback. The argument is validated on conversion: passing a non-function throws TypeError before your code runs.
call(env, args_tuple)
call's second argument is a Zig tuple. Each element is auto-converted to JS. The call uses undefined as this.
You can also pass a []const Val slice when you have one already built:
The return value of call is a napi.Val. Convert it to a Zig type with .to(env, T):
callWith(env, this, args)
For a specific this binding:
Cross-thread: threadsafe(env, name, T)
Calling cb.call from a non-main thread crashes Node. To call back into JS from a worker thread, wrap the callback as a ThreadsafeFn:
The third argument is the per-call payload type. Use void for signal-only callbacks. See Threadsafe functions for the full pattern.