Function asyncMap

Maps over an array with an async function, resolving all promises concurrently. Similar to Promise.all(array.map(...)).

const fetchUser = (id: number) => fetch(`/api/users/${id}`);
await asyncMap(fetchUser)([1, 2, 3]);
// => [User, User, User]
  • Type Parameters

    • T

      Input element type

    • U

      Output element type

    Parameters

    • fn: (item: T) => Promise<U>

      Async function to apply to each element

    Returns (array: readonly T[]) => Promise<U[]>

    Promise resolving to array of mapped values