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

    Function withTimeout

    • Execute a promise with a timeout

      Races the provided promise against a timeout. If the timeout expires before the promise resolves, a TimeoutError is thrown.

      Type Parameters

      • T

        Type of the promise result

      Parameters

      • promise: Promise<T>

        Promise to execute with timeout

      • timeoutMs: number

        Timeout in milliseconds

      • OptionalerrorMessage: string

        Optional custom error message

      Returns Promise<T>

      Promise that resolves with the result or rejects with TimeoutError

      If operation exceeds timeout

      const result = await withTimeout(
      fetchFromAPI('/endpoint'),
      5000,
      'API request timed out'
      );
      • Prevents resource exhaustion from hanging operations
      • Ensures responsive API behavior
      • Timeout values should be tuned per operation

      0.8.0