Files
scriptc/tests/corpus/native-worker-clone-errors.ts
Chris Tate 095b619330 Add native workers and shared memory
- Add native worker execution with isolated module state, structured messages, and lifecycle controls.
- Support shared buffers and integer atomics with coordinated runtime ownership and cancellation.
- Extend compiler, runtime-pack, differential, and compatibility coverage for native concurrency.
2026-10-07 19:07:02 -05:00

18 lines
605 B
TypeScript

import { Worker, isMainThread, parentPort } from "node:worker_threads";
if (isMainThread) {
const worker = new Worker(new URL(import.meta.url));
try {
worker.postMessage(() => {});
} catch (error) {
if (error instanceof Error) console.log("clone", error.name);
else throw error;
}
const transfer: unknown[] = [];
worker.postMessage(42, transfer);
worker.on("message", (value: unknown) => console.log("reply", value));
worker.on("exit", (code: number) => console.log("exit", code));
} else {
parentPort!.once("message", (value: unknown) => parentPort!.postMessage(value));
}