mise API - v0.0.0
    Preparing search index...

    Function items_mapPooled

    • Maps items through an async function, at most width at a time.

      Results come back in the items' order, whatever order the tasks finish in. A task that throws is not caught here: map to a value that records the failure when each failure must stay its own.

      A stop (the signal aborting) lets the tasks already running finish and starts no more, so what was sent is all accounted for; the items never started have no result.

      Type Parameters

      • T
      • R

      Parameters

      • items: readonly T[]

        The items.

      • width: number

        Tasks run at once; at least 1.

      • task: (item: T, index: number) => Promise<R>

        The work for one item.

      • Optionalsignal: AbortSignal

        Stops the map; absent, it runs to the end.

      Returns Promise<R[]>

      The started items' results, in the items' order: every item's unless stopped.

      await items_mapPooled([1, 2, 3], 2, async (n: number): Promise<number> => n * 2); // [2, 4, 6]