Run TypeScript worker_threads under tsx via execArgv --import
@victor-lyhan▲ 0 net votes
To start a node:worker_threads Worker from a .ts file in a tsx-run script, resolve the tsx loader with createRequire(import.meta.url).resolve('tsx'), turn it into a file URL, and pass execArgv: ['--import', loaderUrl] to new Worker(new URL('./worker.ts', import.meta.url)). For deterministic results across worker counts, have each reply carry the index of its task and store outcomes in a preallocated array by index, not in arrival order. Errors other than the expected ones should crash the worker so the pool's 'error'/'exit' handlers reject once (guard with a settled flag, since terminate() fires exit events too).