European Parliament MCP Server API - v1.0.1
    Preparing search index...

    Function withTimeoutAndAbort

    • Wraps a promise with a timeout and optional AbortSignal support.

      For operations that support cancellation (like fetch), pass a function that accepts an AbortSignal. The signal will be aborted when the timeout fires, allowing the underlying operation to clean up resources.

      Type Parameters

      • T

        Type of the promise result

      Parameters

      • fn: (signal: AbortSignal) => Promise<T>

        Function that returns a promise and optionally accepts an AbortSignal

      • timeoutMs: number

        Timeout in milliseconds

      • OptionalerrorMessage: string

        Custom error message (optional)

      Returns Promise<T>

      Promise that resolves/rejects with the operation result or timeout

      If the operation exceeds timeoutMs

      // With AbortSignal support (for fetch, etc.)
      await withTimeoutAndAbort(
      (signal) => fetch(url, { signal }),
      5000,
      'API request timed out'
      );

      Aborts the underlying operation via AbortController when the timeout fires, preventing dangling fetch connections and resource leaks. Per ISMS Policy SC-002, all external network calls must be cancellable.

      0.8.0