edgeport - v1.0.6
    Preparing search index...

    Function withTimeout

    • Rejects with TimeoutError if promise does not settle within ms milliseconds.

      When ms is undefined or Infinity the original promise is returned unchanged (no timer is armed), so a caller can pass an optional deadline straight through. Otherwise the returned promise settles with whichever happens first: promise resolving/rejecting, or the deadline elapsing. The internal timer is always cleared once the race settles.

      Type Parameters

      • T

        The resolved value of promise.

      Parameters

      • promise: Promise<T>

        The operation to bound.

      • ms: number | undefined

        The deadline in milliseconds; undefined/Infinity disables the timeout.

      • Optionallabel: string

        A short name for the operation, used in the timeout message (default "operation").

      Returns Promise<T>

      A promise that settles with promise's result or rejects with TimeoutError.

      If the deadline elapses before promise settles.

      1.0.4

      import { withTimeout } from 'edgeport/util';

      // reject if the fetch has not resolved within 5 seconds
      const res = await withTimeout(fetch('https://example.com'), 5000, 'fetch');