【发布时间】:2021-05-06 12:03:27
【问题描述】:
我正在使用集群(节点 js),我希望每个工作人员使用数组的第一个元素,我想使用这种方法,因为我不想使用 for 循环
Multi_processing = (() => {
let name;
x = [1,2,3,4]
return async() => {
if (cluster.isMaster) {
// name = await prompt(' input ');// input which I want to be reused in else
console.log(`Master ${process.pid} is running`);
for (let i = 0; i <2; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} finished`);
});
} else {
console.log(x.shift()) // name is undefined
console.log(`Worker ${process.pid} started`);
console.log(x)
}
};
})();
Multi_processing();
所以我这样做了,所以第一个开始使用第一个元素的工人然后删除它等等。
【问题讨论】:
标签: javascript node.js arrays list multiprocessing