node-ctypes - v2.17.1
    Preparing search index...

    Function threadSafeCallback

    • 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.

      Type Parameters

      • TRet extends CallbackRestype
      • const TArgs extends readonly FFIType[] = readonly []

      Parameters

      • fn: (...args: CallbackArgs<TArgs>) => CallbackResult<TRet>

        JavaScript function to wrap

      • returnType: TRet

        Return type of the callback

      • OptionalargTypes: TArgs

        Argument types

      • Optionaloptions:
            | "cdecl"
            | "stdcall"
            | "fastcall"
            | "thiscall"
            | "default"
            | ThreadSafeCallbackOptions

      Returns ThreadSafeCallbackWrapper