@rcompat/worker
v0.18.0
Published
Standard library workers
Readme
@rcompat/worker
This module provides portable module workers with the Web Worker event and messaging contract.
Installation
npm install @rcompat/workerpnpm add @rcompat/workeryarn add @rcompat/workerbun add @rcompat/workerUsage
import Worker from "@rcompat/worker";
const worker = new Worker(new URL("./worker.js", import.meta.url), {
name: "example",
});
worker.addEventListener("message", event => {
console.log(event.data);
});
worker.postMessage("hello");The package exposes the Worker interface in
browsers, Bun, Deno, and Node.
Node workers are bootstrapped with self, postMessage, onmessage, and the
standard event-target methods so the same module worker can run in every
supported runtime.
Workers are always ES modules, so the module mode can normally be omitted from the optional constructor options.
Worker scripts should use the Web Worker messaging API rather than
runtime-specific APIs such as Node's parentPort.
