An unsafe function pointer for passing JavaScript functions as C function pointers to foreign function calls.
The function pointer remains valid until the close()
method is called.
All UnsafeCallback
are always thread safe in that they can be called from
foreign threads without crashing. However, they do not wake up the Deno event
loop by default.
If a callback is to be called from foreign threads, use the threadSafe()
static constructor or explicitly call ref()
to have the callback wake up
the Deno event loop when called from foreign threads. This also stops
Deno's process from exiting while the callback still exists and is not
unref'ed.
Use deref()
to then allow Deno's process to exit. Calling deref()
on
a ref'ed callback does not stop it from waking up the Deno event loop when
called from foreign threads.
Constructors Jump to heading
Jump to headingUnsafeCallback(definition: Definition,callback: UnsafeCallbackFunction<Definition["parameters"], Definition["result"]>,)
Type Parameters Jump to heading
Jump to headingDefinition extends UnsafeCallbackDefinition = UnsafeCallbackDefinition
Properties Jump to heading
Jump to headingcallback: UnsafeCallbackFunction<Definition["parameters"], Definition["result"]>
The callback function.
Jump to headingdefinition: Definition
The definition of the unsafe callback.
Jump to headingpointer: PointerObject<Definition>
The pointer to the unsafe callback.
Methods Jump to heading
Jump to headingclose(): void
Removes the C function pointer associated with this instance.
Continuing to use the instance or the C function pointer after closing
the UnsafeCallback
will lead to errors and crashes.
Calling this method sets the callback's reference counting to zero, stops the callback from waking up the Deno event loop when called from foreign threads and no longer keeps Deno's process from exiting.
Jump to headingref(): number
Increments the callback's reference counting and returns the new reference count.
After ref()
has been called, the callback always wakes up the
Deno event loop when called from foreign threads.
If the callback's reference count is non-zero, it keeps Deno's process from exiting.
Jump to headingunref(): number
Decrements the callback's reference counting and returns the new reference count.
Calling unref()
does not stop a callback from waking up the Deno
event loop when called from foreign threads.
If the callback's reference counter is zero, it no longer keeps Deno's process from exiting.
Static Methods Jump to heading
Jump to headingthreadSafe<Definition extends UnsafeCallbackDefinition = UnsafeCallbackDefinition>(definition: Definition,callback: UnsafeCallbackFunction<Definition["parameters"], Definition["result"]>,): UnsafeCallback<Definition>
Creates an UnsafeCallback
and calls ref()
once to allow it to
wake up the Deno event loop when called from foreign threads.
This also stops Deno's process from exiting while the callback still exists and is not unref'ed.