Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/mapSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ import awaitify from './internal/awaitify.js'
* functions have finished, or an error occurs. Results is an array of the
* transformed items from the `coll`. Invoked with (err, results).
* @returns {Promise} a promise, if no callback is passed
* @example
*
* // One item at a time. Results stay in input order.
* const ids = [1, 2, 3];
*
* function fetchItem(id, callback) {
* setTimeout(() => {
* callback(null, { id });
* }, 100);
* }
*
* async.mapSeries(ids, fetchItem, (err, results) => {
* if (err) throw err;
* console.log(results);
* // [ { id: 1 }, { id: 2 }, { id: 3 } ]
* });
*
* // Omit the callback and mapSeries returns a Promise.
* const results = await async.mapSeries(ids, async (id) => {
* return { id };
* });
* console.log(results);
* // [ { id: 1 }, { id: 2 }, { id: 3 } ]
*/
function mapSeries (coll, iteratee, callback) {
return _map(eachOfSeries, coll, iteratee, callback)
Expand Down