Ende.UnsafeCallback
class
class Ende.UnsafeCallback<Definition extends UnsafeCallbackDefinition = UnsafeCallbackDefinition>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 Ende 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 Ende event loop when called from foreign threads. This also stops
Ende's process from exiting while the callback still exists and is not
unref'ed.
Use deref() to then allow Ende's process to exit. Calling deref() on
a ref'ed callback does not stop it from waking up the Ende event loop when
called from foreign threads.
Constructors
constructor
new UnsafeCallback(definition: Definition, callback: UnsafeCallbackFunction<Definition["parameters"], Definition["result"]>)Static methods
threadSafe
static threadSafe<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 Ende event loop when called from foreign threads.
This also stops Ende's process from exiting while the callback still exists and is not unref'ed.
Properties
pointer
readonly pointer: PointerObject<Definition>The pointer to the unsafe callback.
definition
readonly definition: DefinitionThe definition of the unsafe callback.
callback
readonly callback: UnsafeCallbackFunction<Definition["parameters"], Definition["result"]>The callback function.
Methods
ref
ref(): numberIncrements the callback's reference counting and returns the new reference count.
After ref() has been called, the callback always wakes up the
Ende event loop when called from foreign threads.
If the callback's reference count is non-zero, it keeps Ende's process from exiting.
unref
unref(): numberDecrements the callback's reference counting and returns the new reference count.
Calling unref() does not stop a callback from waking up the Ende
event loop when called from foreign threads.
If the callback's reference counter is zero, it no longer keeps Ende's process from exiting.
close
close(): voidRemoves 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 Ende event loop when called from foreign threads and no longer keeps Ende's process from exiting.