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

    Function withTimeout

    • Races promise against a timeout. Rejects with a TimeoutError if ms elapses first.

      Type Parameters

      • T

      Parameters

      • promise: Promise<T>

        The promise to race.

      • ms: number

        Timeout duration in milliseconds.

      Returns Promise<T>

      const data = await withTimeout(fetch("/api"), 5000)
      // throws if the fetch takes longer than 5 seconds