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.
14 lines
503 B
JavaScript
14 lines
503 B
JavaScript
const { Worker, isMainThread, parentPort, workerData } = require("node:worker_threads");
|
|
|
|
if (isMainThread) {
|
|
const worker = new Worker(__filename, { workerData: 41 });
|
|
worker.on("message", (value) => console.log("result", value));
|
|
worker.on("exit", async (code) => {
|
|
// A completed Worker discards even uncloneable payloads.
|
|
worker.postMessage(() => {});
|
|
console.log("exit", code, worker.threadId, await worker.terminate());
|
|
});
|
|
} else {
|
|
parentPort.postMessage(workerData + 1);
|
|
}
|