times-loop
Version:
run a function n times, both sync and async functions are supported
26 lines • 804 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.timesSeries = exports.timesParallel = void 0;
function times(count, callback) {
const results = [];
for (var i = 0; i < count; i++) {
results.push(callback(i));
}
return results;
}
exports.default = times;
function timesParallel(count, callback) {
const promises = times(count, callback);
return Promise.all(promises);
}
exports.timesParallel = timesParallel;
function timesSeries(count, callback) {
let lastPromise;
const promises = times(count, (i) => {
lastPromise = i === 0 ? callback(i) : lastPromise.then(() => callback(i));
return lastPromise;
});
return Promise.all(promises);
}
exports.timesSeries = timesSeries;
//# sourceMappingURL=index.js.map