1'use strict'; 2 3if (require.main !== module) { 4 const { spawnSync } = require('child_process'); 5 6 function runModuleAs(filename, flags, spawnOptions, role) { 7 return spawnSync(process.execPath, 8 [...flags, __filename, role, filename], spawnOptions); 9 } 10 11 module.exports = runModuleAs; 12 return; 13} 14 15const { Worker, isMainThread, workerData } = require('worker_threads'); 16 17if (isMainThread) { 18 if (process.argv[2] === 'worker') { 19 new Worker(__filename, { 20 workerData: process.argv[3] 21 }); 22 return; 23 } 24 require(process.argv[3]); 25} else { 26 require(workerData); 27} 28