mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
- 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.
13 lines
481 B
TypeScript
13 lines
481 B
TypeScript
import { Worker, isMainThread, parentPort } from "node:worker_threads";
|
|
if (isMainThread) {
|
|
const worker = new Worker(new URL(import.meta.url));
|
|
worker.on("message", async () => {
|
|
console.log("ready");
|
|
console.log("terminated", await worker.terminate());
|
|
});
|
|
worker.on("exit", (code: number) => console.log("exit", code));
|
|
} else {
|
|
parentPort!.postMessage("ready");
|
|
try { while (true) {} } catch { console.log("caught"); } finally { console.log("finally"); }
|
|
}
|