@eroyeroy/utils - v0.1.0
    Preparing search index...

    Function parallel

    • Runs async tasks in parallel with an optional concurrency limit. Results are returned in the same order as the input tasks.

      Type Parameters

      • T

      Parameters

      • tasks: (() => Promise<T>)[]

        Array of functions that each return a promise.

      • concurrency: number = Infinity

        Maximum number of tasks running at once. Defaults to Infinity.

      Returns Promise<T[]>

      const results = await parallel([
      () => fetchUser(1),
      () => fetchUser(2),
      () => fetchUser(3),
      ], 2)
      // fetches at most 2 users at a time