mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 18:15:18 +00:00

PR-URL: https://github.com/nodejs/node/pull/45550 Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
28 lines
605 B
JavaScript
28 lines
605 B
JavaScript
'use strict';
|
|
|
|
if (require.main !== module) {
|
|
const { spawnSync } = require('child_process');
|
|
|
|
function runModuleAs(filename, flags, spawnOptions, role) {
|
|
return spawnSync(process.execPath,
|
|
[...flags, __filename, role, filename], spawnOptions);
|
|
}
|
|
|
|
module.exports = runModuleAs;
|
|
return;
|
|
}
|
|
|
|
const { Worker, isMainThread, workerData } = require('worker_threads');
|
|
|
|
if (isMainThread) {
|
|
if (process.argv[2] === 'worker') {
|
|
new Worker(__filename, {
|
|
workerData: process.argv[3],
|
|
});
|
|
return;
|
|
}
|
|
require(process.argv[3]);
|
|
} else {
|
|
require(workerData);
|
|
}
|