promise.ts 302 B

12345678910111213
  1. /**
  2. * run `fn` in series for all values, and resolve with an array of the results
  3. */
  4. export const mapSeries = async <T = any, V = any>(
  5. values: T[],
  6. fn: (item: T) => Promise<V>
  7. ) => {
  8. const output: V[] = []
  9. for (const value of values) {
  10. output.push(await fn(value))
  11. }
  12. return output
  13. }