UNPKG

@beenotung/tslib

Version:
17 lines (16 loc) 520 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parallel_run = parallel_run; // to batch process async operation in parallel, e.g. downloading files async function parallel_run(xs, f, n_partition) { async function run_partition(offset) { for (let i = offset; i < xs.length; i += n_partition) { await f(xs[i]); } } const ps = []; for (let i = 0; i < n_partition; i++) { ps.push(run_partition(i)); } await Promise.all(ps); }