blob: 9703ac8f63ae0a5d231981b85d33e454c3ce38f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
import fs from "node:fs/promises";
import { isMainThread, Worker } from "node:worker_threads";
await fs.writeFile("mod.mjs", "export default " + isMainThread);
const path = new URL("mod.mjs", import.meta.url);
const i = await import(path.href);
console.log(i);
if (isMainThread) {
const worker = new Worker(new URL("main.ts", import.meta.url));
worker.on("message", (msg) => console.log(msg));
}
|