Exit from a NodeJS script when all asynchronous tasks are done

前端 未结 1 2012
渐次进展
渐次进展 2020-12-19 01:49

I\'m executing some asynchronous process with firebase with NodeJS.

I\'d like to stop when finish all tasks the NodeJS process execution without the need of Ctrl+C c

相关标签:
1条回答
  • 2020-12-19 02:08

    First, all your asynchronous processes should be promises, then you wrap all of these promises in a single promise with Promise.all and exit when that promise resolves. Like this:

    Promise.all([
    
     promiseForAsynchronousProcess1,
     promiseForAsynchronousProcess2,
     promiseForAsynchronousProcess3,
     ... and so on...
    
    ]).then(process.exit);
    
    0 讨论(0)
提交回复
热议问题