0

我有一个将消息传递给子进程以在循环中间进行处理的进程,然后应该继续取决于子进程的响应。

但是,我不知道如何暂停循环以允许子进程在我们收到消息后完成并继续。

这是函数的样子

function runTests()
{
  allTests = getTests()
  allTests.forEach(test => {
    console.log(chalk.blue.bold.underline('Running: '+ test.title))
    for(i = 0;i < test.questions.length;i++)
    {
      //Fork child process. 
      const poll = fork('poll.js',['999999', new Date()])
      poll.send(test.questions[i])
      poll.on('message', msg => {

     if(assert("msg.includes('error')",msg))
     {
      console.log(chalk.blue.bold.underline('Child response: '+ msg))
     }
  });
 }
}) 
}
4

0 回答 0