mirror of
https://github.com/strapi/strapi.git
synced 2025-12-25 06:04:29 +00:00
chore(async-utils): move jsdoc to ts typings
This commit is contained in:
parent
50ee8882cd
commit
1f4b7c196e
10
packages/core/utils/lib/async.d.ts
vendored
Normal file
10
packages/core/utils/lib/async.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
type PromiseArray<T> = (T | Promise<T>)[];
|
||||
|
||||
type MapIteratee<T, R = T> = (value: T, index: number) => R | Promise<R>;
|
||||
|
||||
type ReduceIteratee<P, C = P, R = P> = (previousResult: P, currentValue: C, index: number) => R | Promise<R>;
|
||||
|
||||
export declare function mapAsync<T = unknown>(promiseArray: PromiseArray<T>): <R = T>(iteratee: MapIteratee<T, R>) => Promise<R[]>;
|
||||
|
||||
export declare function reduceAsync<T = unknown>(promiseArray: PromiseArray<T>): <R = unknown, I>(iteratee: ReduceIteratee<I | R, T, R>, initialValue?: I) => Promise<R>;
|
||||
@ -13,21 +13,9 @@ function pipeAsync(...methods) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Map function callback.
|
||||
* @callback mapAsyncCallback
|
||||
* @param {*} value
|
||||
* @param {number} index
|
||||
*/
|
||||
/**
|
||||
* Async iteration over an array of promises
|
||||
* @param {promise<*>[]} promiseArray
|
||||
* @returns {function(callback: mapAsyncCallback): promise<*[]>}
|
||||
* @type { import('./async').mapAsync }
|
||||
*/
|
||||
function mapAsync(promiseArray) {
|
||||
/**
|
||||
* @param {mapAsyncCallback} callback
|
||||
* @returns promise<*[]>
|
||||
*/
|
||||
return (callback) => {
|
||||
const transformedPromiseArray = promiseArray.map(async (promiseValue, index) => {
|
||||
const value = await promiseValue;
|
||||
@ -38,23 +26,9 @@ function mapAsync(promiseArray) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce function callback.
|
||||
* @callback reduceAsyncCallback
|
||||
* @param {*} previousValue
|
||||
* @param {*} currentValue
|
||||
* @param {number} index
|
||||
*/
|
||||
/**
|
||||
* Async chain over an array of promises
|
||||
* @param {promise<*>[]} promiseArray
|
||||
* @returns {function(callback: reduceAsyncCallback, initialValue?: *): promise<*>}
|
||||
* @type { import('./async').reduceAsync }
|
||||
*/
|
||||
function reduceAsync(promiseArray) {
|
||||
/**
|
||||
* @param {reduceAsyncCallback} callback
|
||||
* @param {*} [initialValue]
|
||||
* @returns promise<*>
|
||||
*/
|
||||
return (callback, initialValue) =>
|
||||
promiseArray.reduce(async (previousPromise, currentValue, index) => {
|
||||
const previousValue = await previousPromise;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user