times-loop
Version:
run a function n times, both sync and async functions are supported
20 lines • 603 B
JavaScript
export default function times(count, callback) {
const results = [];
for (var i = 0; i < count; i++) {
results.push(callback(i));
}
return results;
}
export function timesParallel(count, callback) {
const promises = times(count, callback);
return Promise.all(promises);
}
export 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);
}
//# sourceMappingURL=index.js.map