I have an async function that takes a callback
function doAsync(delay, cb) {
setTimeout(() => {
console.log('async ', delay);
cb();
}, delay);
}
I want to call this function a number of times and be notified when all callbacks are done.
// I have to call `doAsync` for each element of this array
var a = [100,300,200,400];
a.forEach(_ => doAsync(_, () => {}));
function onEnd() {
console.log('all done');
}
// expected output
//
// async 100
// async 200
// async 300
// async 400
// all done