How to wait for a stream to finish piping? (Nodejs)

后端 未结 3 1143
臣服心动
臣服心动 2020-12-05 04:13

I have a for loop array of promises, so I used Promise.all to go through them and called then afterwards.

let promises = [];
promises.push(promise1);
promise         


        
3条回答
  •  醉梦人生
    2020-12-05 04:46

    Without async/await, it's quite nasty. With async/await, just do this:

    Promise.all(promises).then(async (responses) => {
      for (...) {
        await new Promise(fulfill => stream.on("finish", fulfill));
        //extract the text out of the PDF
      }
    })
    

提交回复
热议问题