Skip to content

Worker hooks

Generated from crates/niso-core/include/worker-hooks.h when the site was built at 7aa23e2.

This is the worker-hooks section of niso_runtime.h, owned by niso-messaging and kept in crates/niso-core/include/worker-hooks.h. The build composes it with the other sections in the order crates/niso-compose/sections.txt gives.

The C surface of niso-core’s WorkerHost trait (worker.rs): the runner is a worker host that starts a thread itself. Setting the runner leaves the host and the reverse; the host’s start is used while it is set. Null is none, and with neither set new Worker is NotSupported. The userdata stays the host’s.

Runs a dedicated worker, on the worker’s own thread, given its DOM: makes a JS engine for it, runs the script niso_dedicated_worker_global_scope_script returns (or reports niso_dedicated_worker_global_scope_script_failed), calls niso_dom_worker_started, then runs niso_dom_run until niso_dom_worker_closing, then frees the engine. The core frees the DOM.

typedef void (*niso_worker_runner_fn)(niso_dom* dom);

A worker host, for a host that owns threads and their event loops: start starts a thread with a realm of its own that calls niso_worker_begin(worker) and returns at once, false if it cannot; terminate stops the script of a worker whose thread began, even one that never returns to its loop. Both are called on the thread of the DOM that started the worker.

typedef bool (*niso_worker_start_fn)(void* userdata, uint64_t worker);
typedef void (*niso_worker_terminate_fn)(void* userdata, uint64_t worker);