JSFiddle - React, Tailwind, and code Playground
by Dogbert
JavaScript
var myAsyncFunction = function (index, next) {
setTimeout(function () {
next("done: " + index);
}, 200);
};
var asyncLoop = function (limit, callback, done) {
var current = 0,
results = [];
var next = function () {
if (current >= limit) {
done(results);
} else {
callback(current, function (result) {
results.push(result);
current++;
next();
});
}
};
next();
};
asyncLoop(10, myAsyncFunction, function(results) {
console.log("results", results);
});