Create a thread-safe callback that can be invoked from any thread.
Important: Call .release() when the callback is no longer needed.
Like a timer, it keeps the Node.js event loop alive until released, unless
.unref() is called.
Deadlock warning: a call from another thread waits for the JavaScript
thread to run the function. A synchronous FFI call on the JavaScript
thread that waits for that other thread (for example WaitForSingleObject
or pthread_join on it) therefore never returns while the callback is
pending. Wait through FFIFunction.callAsync or an Executor
(callOn) instead, so the JavaScript thread stays free to deliver the
callback. While the Node.js environment is being torn down (process exit,
worker.terminate()), an invocation does not wait: it returns zero (the
default value of the result type) and records an error.
Create a thread-safe callback that can be invoked from any thread.
Important: Call
.release()when the callback is no longer needed. Like a timer, it keeps the Node.js event loop alive until released, unless.unref()is called.Deadlock warning: a call from another thread waits for the JavaScript thread to run the function. A synchronous FFI call on the JavaScript thread that waits for that other thread (for example
WaitForSingleObjectorpthread_joinon it) therefore never returns while the callback is pending. Wait through FFIFunction.callAsync or an Executor (callOn) instead, so the JavaScript thread stays free to deliver the callback. While the Node.js environment is being torn down (process exit,worker.terminate()), an invocation does not wait: it returns zero (the default value of the result type) and records an error.