postMessage method
@AvailableInWorkers("dedicated")
The postMessage()
method of the DedicatedWorkerGlobalScope
interface sends a message to the main thread that spawned it.
This accepts a data parameter, which contains data to copy from the worker to the main thread. The data may be any value or JavaScript object handled by the structured clone algorithm, which includes cyclical references.
The method also accepts an optional array of transferable objects to transfer to the main thread; Unlike the data parameter transferred objects are no longer usable in the worker thread. (Where possible, objects are transferred using a high performance zero-copy operation).
The main scope that spawned the worker can send back information to the thread that spawned it using the Worker.postMessage method.
Implementation
external void postMessage(
JSAny? message, [
JSObject optionsOrTransfer,
]);