Callback after all asynchronous forEach callbacks are completed

后端 未结 13 2308
谎友^
谎友^ 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:24

    How about setInterval, to check for complete iteration count, brings guarantee. not sure if it won't overload the scope though but I use it and seems to be the one

    _.forEach(actual_JSON, function (key, value) {
    
         // run any action and push with each iteration 
    
         array.push(response.id)
    
    });
    
    
    setInterval(function(){
    
        if(array.length > 300) {
    
            callback()
    
        }
    
    }, 100);
    

提交回复
热议问题