Files
scriptc/tests/corpus/native-worker-loop-cancellation.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

23 lines
811 B
TypeScript

import { Worker, isMainThread, parentPort, workerData } from "node:worker_threads";
if (isMainThread) {
for (const kind of ["for", "do", "for-of"]) {
await new Promise<void>((resolve) => {
const worker = new Worker(new URL(import.meta.url), {workerData: kind});
worker.once("message", () => { worker.terminate(); });
worker.once("exit", (code: number) => { console.log(kind, code); resolve(); });
});
}
} else {
parentPort!.postMessage("ready");
try {
if (workerData === "for") { for (;;) { continue; } }
else if (workerData === "do") { do { continue; } while (true); }
else {
const growing = [1];
for (const value of growing) growing.push(value);
}
} catch { console.log("unexpected catch"); }
finally { console.log("unexpected finally"); }
}