@beenotung/tslib
Version:
utils library in Typescript
23 lines • 829 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parallel_run = void 0;
const tslib_1 = require("tslib");
// to batch process async operation in parallel, e.g. downloading files
function parallel_run(xs, f, n_partition) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
function run_partition(offset) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
for (let i = offset; i < xs.length; i += n_partition) {
yield f(xs[i]);
}
});
}
const ps = [];
for (let i = 0; i < n_partition; i++) {
ps.push(run_partition(i));
}
yield Promise.all(ps);
});
}
exports.parallel_run = parallel_run;
//# sourceMappingURL=parallel-run.js.map