UNPKG

testbook

Version:
16 lines 897 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.promiseBatch = exports.chunk = exports.promiseSequence = void 0; const promiseSequence = (tasks) => tasks.reduce((promiseChain, currentTask) => promiseChain.then((chainResults) => currentTask().then((currentResult) => [...chainResults, currentResult])), Promise.resolve([])); exports.promiseSequence = promiseSequence; const chunk = (items, count) => { let i = 0, result = []; while (i < items.length) { result.push(items.slice(i, (i += count))); } return result; }; exports.chunk = chunk; const promiseBatch = (tasks, batchSize) => exports.promiseSequence(exports.chunk(tasks, batchSize).map((batchedTasks) => () => Promise.all(batchedTasks.map((batchedTask) => batchedTask())))).then((batches) => batches.flat()); exports.promiseBatch = promiseBatch; //# sourceMappingURL=promise.js.map