( items: TInput[], work: (item: TInput, index: number) => Promise<TOutput>, )
| 15 | } |
| 16 | |
| 17 | export async function asyncSequential<TInput, TOutput>( |
| 18 | items: TInput[], |
| 19 | work: (item: TInput, index: number) => Promise<TOutput>, |
| 20 | ): Promise<TOutput[]> { |
| 21 | // for-loop used instead of reduce for performance |
| 22 | const results: TOutput[] = []; |
| 23 | // eslint-disable-next-line functional/no-loop-statements |
| 24 | for (const [index, item] of items.entries()) { |
| 25 | const result = await work(item, index); |
| 26 | // eslint-disable-next-line functional/immutable-data |
| 27 | results.push(result); |
| 28 | } |
| 29 | return results; |
| 30 | } |
| 31 | |
| 32 | export async function settlePromise<T>( |
| 33 | promise: Promise<T>, |
no outgoing calls
no test coverage detected