Skip to content

Instantly share code, notes, and snippets.

@pcan
Last active March 17, 2025 13:18
Show Gist options
  • Save pcan/b5125c95529705169d37bbf353ce53a1 to your computer and use it in GitHub Desktop.
Save pcan/b5125c95529705169d37bbf353ce53a1 to your computer and use it in GitHub Desktop.
Run Worker threads using `tsx`
import { parentPort } from "worker_threads";
parentPort?.on("message", (message) => {
console.log("Received message from main thread:", message);
});
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