Created
March 31, 2021 15:14
-
-
Save bboure/819224f7074844c5b6a87604e2d621e5 to your computer and use it in GitHub Desktop.
@types/chunk-promise TypeScript
This file contains hidden or 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
declare module 'chunk-promise' { | |
type PromiseArray<T> = (() => Promise<T>)[]; | |
type PromiseFlavor = 'PromiseAll' | 'PromiseAllSettled'; | |
type Options<T, F extends PromiseFlavor> = { | |
concurrent?: number; | |
sleepMs?: number; | |
callback?: ( | |
chunkResults: F extends 'PromiseAllSettled' | |
? PromiseSettledResult<T>[] | |
: T[], | |
chunkIndex: number, | |
allResults: F extends 'PromiseAllSettled' | |
? PromiseSettledResult<T>[] | |
: T[], | |
) => Promise<void>; | |
promiseFlavor?: F; | |
logMe?: boolean; | |
}; | |
export function chunkPromise<T, Type extends PromiseFlavor = 'PromiseAll'>( | |
promiseArr: PromiseArray<T>, | |
options: Options<T, Type>, | |
): Type extends 'PromiseAllSettled' | |
? Promise<PromiseSettledResult<T>[] | undefined> | |
: Promise<T[] | undefined>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment