Callback after all asynchronous forEach callbacks are completed

后端 未结 13 2261
谎友^
谎友^ 2020-11-22 12:56

As the title suggests. How do I do this?

I want to call whenAllDone() after the forEach-loop has gone through each element and done some asynchronous p

13条回答
  •  爱一瞬间的悲伤
    2020-11-22 13:25

    You shouldn't need a callback for iterating through a list. Just add the end() call after the loop.

    posts.forEach(function(v, i){
       res.write(v + ". Index " + i);
    });
    res.end();
    

提交回复
热议问题