mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
fix(async): arity for reduce func and awaited value
This commit is contained in:
parent
5b0e7f6903
commit
477750650e
@ -108,7 +108,7 @@ describe('Async utils', () => {
|
||||
await expect(async () => {
|
||||
await reduceFunc(() => {
|
||||
throw new Error('test');
|
||||
});
|
||||
}, null);
|
||||
}).rejects.toThrow('test');
|
||||
});
|
||||
test('Should throw an error 2', async () => {
|
||||
@ -117,7 +117,7 @@ describe('Async utils', () => {
|
||||
const reduceFunc = reduceAsync(numberPromiseArray);
|
||||
|
||||
await expect(async () => {
|
||||
await reduceFunc(() => true);
|
||||
await reduceFunc(() => true, null);
|
||||
}).rejects.toThrow('input');
|
||||
});
|
||||
});
|
||||
|
||||
6
packages/core/utils/lib/async.d.ts
vendored
6
packages/core/utils/lib/async.d.ts
vendored
@ -1,4 +1,6 @@
|
||||
export type MapAsync<T = any, R = any> = lodash.CurriedFunction3<
|
||||
import { CurriedFunction3 } from 'lodash';
|
||||
|
||||
export type MapAsync<T = any, R = any> = CurriedFunction3<
|
||||
T[],
|
||||
(element: T, index: number) => R | Promise<R>,
|
||||
{ concurrency?: number },
|
||||
@ -11,7 +13,7 @@ export type ForEachAsync<T = any, R = any> = (
|
||||
options?: { concurrency?: number }
|
||||
) => Promise<R[]>;
|
||||
|
||||
export type ReduceAsync<T = any, V = T, R = V> = lodash.CurriedFunction3<
|
||||
export type ReduceAsync<T = any, V = T, R = V> = CurriedFunction3<
|
||||
T[],
|
||||
(accumulator: V | R, current: Awaited<T>, index: number) => R | Promise<R>,
|
||||
V,
|
||||
|
||||
@ -26,10 +26,10 @@ const mapAsync = curry(pMap);
|
||||
const reduceAsync = curry(async (mixedArray, iteratee, initialValue) => {
|
||||
let acc = initialValue;
|
||||
for (let i = 0; i < mixedArray.length; i += 1) {
|
||||
acc = await iteratee(acc, mixedArray[i], i);
|
||||
acc = await iteratee(acc, await mixedArray[i], i);
|
||||
}
|
||||
return acc;
|
||||
});
|
||||
}, 2);
|
||||
|
||||
/**
|
||||
* @type { import('./async').ForEachAsync }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user