-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use transifex .download() to download
Undo tr change
- Loading branch information
seotts
authored and
Cori Hudson
committed
Sep 20, 2022
1 parent
842704f
commit dd2ed99
Showing
6 changed files
with
5,230 additions
and
3,833 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Maps each value of an array into an async function, and returns an array of the results | ||
* @param {array} arr - array of values | ||
* @param {number} batchSize - number of calls to `func` to do at one time | ||
* @param {function} func - async function to apply to all items in `arr`. Function should take one argument. | ||
* @return {array} - results of `func` applied to each item in `arr` | ||
*/ | ||
exports.batchMap = async (arr, batchSize, func) => { | ||
const results = []; | ||
for (let i = 0; i < arr.length; i += batchSize) { | ||
const result = await Promise.all( // eslint-disable-line | ||
arr.slice(i, i + batchSize).map(func) | ||
); | ||
results.push(...result); | ||
} | ||
return results; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.