mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-21 05:50:55 +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.
18 lines
605 B
TypeScript
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));
|
|
}
|