chore(async-utils): renaming callbacks in iteratee

This commit is contained in:
nathan-pichon 2022-12-20 12:03:59 +01:00
parent eb83b3c3fa
commit 49a61a93a7
No known key found for this signature in database

View File

@ -21,7 +21,7 @@ function mapAsync(promiseArray, { concurrency = Infinity } = {}) {
const appliedConcurrency = concurrency > promiseArray.length ? promiseArray.length : concurrency; const appliedConcurrency = concurrency > promiseArray.length ? promiseArray.length : concurrency;
const promiseArrayChunks = chunk(appliedConcurrency)(promiseArray); const promiseArrayChunks = chunk(appliedConcurrency)(promiseArray);
return async (callback) => { return async (iteratee) => {
return promiseArrayChunks.reduce(async (prevChunksPromise, chunk, chunkIndex) => { return promiseArrayChunks.reduce(async (prevChunksPromise, chunk, chunkIndex) => {
// Need to await previous promise in order to respect the concurrency option // Need to await previous promise in order to respect the concurrency option
const prevChunks = await prevChunksPromise; const prevChunks = await prevChunksPromise;
@ -29,7 +29,7 @@ function mapAsync(promiseArray, { concurrency = Infinity } = {}) {
const awaitedChunk = await Promise.all(chunk); const awaitedChunk = await Promise.all(chunk);
const transformedPromiseChunk = await Promise.all( const transformedPromiseChunk = await Promise.all(
// Calculating the index based on the original array, we do not want to have the index of the element inside the chunk // Calculating the index based on the original array, we do not want to have the index of the element inside the chunk
awaitedChunk.map((value, index) => callback(value, chunkIndex * appliedConcurrency + index)) awaitedChunk.map((value, index) => iteratee(value, chunkIndex * appliedConcurrency + index))
); );
return prevChunks.concat(transformedPromiseChunk); return prevChunks.concat(transformedPromiseChunk);
@ -41,10 +41,10 @@ function mapAsync(promiseArray, { concurrency = Infinity } = {}) {
* @type { import('./async').reduceAsync } * @type { import('./async').reduceAsync }
*/ */
function reduceAsync(promiseArray) { function reduceAsync(promiseArray) {
return (callback, initialValue) => return (iteratee, initialValue) =>
promiseArray.reduce(async (previousPromise, currentValue, index) => { promiseArray.reduce(async (previousPromise, currentValue, index) => {
const previousValue = await previousPromise; const previousValue = await previousPromise;
return callback(previousValue, await currentValue, index); return iteratee(previousValue, await currentValue, index);
}, Promise.resolve(initialValue)); }, Promise.resolve(initialValue));
} }