How can I wait for set of asynchronous callback functions?

前端 未结 6 1799
感动是毒
感动是毒 2020-11-22 09:07

I have code that looks something like this in javascript:

forloop {
    //async call, returns an array to its callback
}

After ALL of those

6条回答
  •  盖世英雄少女心
    2020-11-22 09:48

    Use an control flow library like after

    after.map(array, function (value, done) {
        // do something async
        setTimeout(function () {
            // do something with the value
            done(null, value * 2)
        }, 10)
    }, function (err, mappedArray) {
        // all done, continue here
        console.log(mappedArray)
    })
    

提交回复
热议问题