@newdash/newdash
Version:
javascript/typescript utility library
35 lines (34 loc) • 734 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.series = void 0;
/**
* run async operations one by one, serially
*
* and return the result array
*
* if any operation raise error, the following operations will not be executed
*
* @since 5.14.0
* @category Async
* @param asyncOperations async operations
*
*
* @example
*
* ```js
* const [res1, res2, res3] = await series(
* () => fetch(1),
* () => fetch(2),
* () => fetch(3)
* )
* ```
*/
async function series(...asyncOperations) {
const rt = [];
for (const asyncOperation of asyncOperations) {
rt.push(await asyncOperation());
}
return rt;
}
exports.series = series;
exports.default = series;