0
我想触发一个功能,当两个child_process
已经完成。我想下面使用的承诺,但它似乎触发Promise.all
的承诺得到解决如何知道当两个子进程已解决的NodeJS
let excelParserChildOnePromise = new Promise((resolveChild, rejectChild) => {
let excelParserChildOne = fork(excelParserTool);
excelParserChildOne.send(`${tempFilePositionOne}`);
excelParserChildOne.on('message', (excelArray) => {
console.log('child one resolved')
resolveChild(excelArray);
})
});
let excelParserChildTwoPromise = new Promise((resolveChild, rejectChild) => {
let excelParserChildTwo = fork(excelParserTool);
excelParserChildTwo.send(`${tempFilePositionTwo}`);
excelParserChildTwo.on('message', (excelArray) => {
console.log('child two resolved')
resolveChild(excelArray)
})
});
childPromises.push([excelParserChildOnePromise, excelParserChildTwoPromise]);
Promise.all(childPromises).then(() => {
console.log('inside promise all');
})
此打印出之前,以下
inside promise all
child one resolved
child two resolved
我怎么听当这两个过程完成?
啊..花了我20分钟反正实现 – forJ
感谢... – forJ