Tweakr
    Preparing search index...

    Function raceAll

    • Runs multiple async tasks concurrently and resolves/rejects with the result of the first task that settles.

      This is a thin wrapper around Promise.race for arrays of async task functions.

      Type Parameters

      • T

      Parameters

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

        An array of functions returning promises.

      Returns Promise<T>

      A promise that resolves or rejects with the first task to settle.

      const result = await raceAll([
      () => fetch("/api/slow"),
      () => fetch("/api/fast")
      ]);
      // Resolves as soon as the faster fetch completes

      1.1.0