Last active
March 17, 2025 13:18
-
-
Save pcan/b5125c95529705169d37bbf353ce53a1 to your computer and use it in GitHub Desktop.
Run Worker threads using `tsx`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { parentPort } from "worker_threads"; | |
parentPort?.on("message", (message) => { | |
console.log("Received message from main thread:", message); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Worker } from "worker_threads"; | |
import path from "path"; | |
const worker = new Worker(path.resolve(__dirname, "./worker.ts"), { | |
execArgv: ['-r', 'tsx/cjs'] | |
}); | |
worker.postMessage("Hello, worker!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment