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