deno.com

method Worker.postMessage

Overload 1

#Worker.postMessage(
message: any,
transfer: Transferable[],
): void

Sends a message to the worker, transferring ownership of the specified transferable objects.

Examples #

#
// Create a buffer to transfer (not copy) to the worker
const buffer = new ArrayBuffer(1024);
worker.postMessage({ data: buffer }, [buffer]);
// After transfer, buffer is no longer usable in the main thread

Parameters #

#message: any
#transfer: Transferable[]

Return Type #

void

Overload 2

#Worker.postMessage(
message: any,
): void

Sends a message to the worker.

Examples #

#
// Send a simple message with data
worker.postMessage({
  command: "process",
  data: [1, 2, 3, 4],
  settings: { optimize: true }
});

Parameters #

#message: any
#options: StructuredSerializeOptions
optional

Return Type #

void