Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
12345678910111213141516171819202122232425// Exit codes: a natural exit, process.exit(3) inside the worker (which ends the thread,// not the process), and terminate().const { Worker } = require("node:worker_threads");
const run = (source, label) => new Promise((resolve) => { const w = new Worker(source, { eval: true }); w.on("exit", (code) => { console.log(label, "exit", code); resolve(w); }); return w;});
(async () => { await run("setTimeout(() => {}, 5)", "natural"); await run("process.on('exit', (c) => console.log('worker exit listener', c)); process.exit(3); console.log('unreachable')", "explicit"); const w = new Worker("setInterval(() => {}, 1000)", { eval: true }); w.on("exit", (code) => console.log("terminated exit", code)); w.on("online", async () => { const code = await w.terminate(); console.log("terminate resolved", code); console.log("main still alive"); });})();