From 49a61a93a7cde154fb0a75c0bb67e6caea7ecb10 Mon Sep 17 00:00:00 2001 From: nathan-pichon Date: Tue, 20 Dec 2022 12:03:59 +0100 Subject: [PATCH] chore(async-utils): renaming callbacks in iteratee --- packages/core/utils/lib/async.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/utils/lib/async.js b/packages/core/utils/lib/async.js index 058544fc12..c6e3041323 100644 --- a/packages/core/utils/lib/async.js +++ b/packages/core/utils/lib/async.js @@ -21,7 +21,7 @@ function mapAsync(promiseArray, { concurrency = Infinity } = {}) { const appliedConcurrency = concurrency > promiseArray.length ? promiseArray.length : concurrency; const promiseArrayChunks = chunk(appliedConcurrency)(promiseArray); - return async (callback) => { + return async (iteratee) => { return promiseArrayChunks.reduce(async (prevChunksPromise, chunk, chunkIndex) => { // Need to await previous promise in order to respect the concurrency option const prevChunks = await prevChunksPromise; @@ -29,7 +29,7 @@ function mapAsync(promiseArray, { concurrency = Infinity } = {}) { const awaitedChunk = await Promise.all(chunk); 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 - awaitedChunk.map((value, index) => callback(value, chunkIndex * appliedConcurrency + index)) + awaitedChunk.map((value, index) => iteratee(value, chunkIndex * appliedConcurrency + index)) ); return prevChunks.concat(transformedPromiseChunk); @@ -41,10 +41,10 @@ function mapAsync(promiseArray, { concurrency = Infinity } = {}) { * @type { import('./async').reduceAsync } */ function reduceAsync(promiseArray) { - return (callback, initialValue) => + return (iteratee, initialValue) => promiseArray.reduce(async (previousPromise, currentValue, index) => { const previousValue = await previousPromise; - return callback(previousValue, await currentValue, index); + return iteratee(previousValue, await currentValue, index); }, Promise.resolve(initialValue)); }