@bugbug-io/sdk
    Preparing search index...

    Class RateLimiter

    Token-bucket-ish rate limiter with exponential backoff.

    Used internally by BugBugApiClient. Integrators rarely instantiate this directly; instead pass RateLimitConfig via BugBugConfig.rateLimit.

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Execute a function with rate limiting and exponential backoff.

      The retry loop fires when:

      1. The client-side gate trips (canMakeRequest() returns false) — fn was never called.
      2. The function throws RateLimitError (typically a server 429) AND retryServer429 is enabled. Retrying server 429s on non-idempotent requests (POST startRun, POST startRun) can produce duplicate resources — set retryServer429: false to disable.

      Type Parameters

      • T

      Parameters

      • fn: () => Promise<T>

        The function to execute under rate limiting.

      • options: RateLimiterExecuteOptions = {}

      Returns Promise<T>

      The function's resolved value.

      When retries are exhausted or retryServer429 is disabled and the server returned 429.

    • Snapshot of the current rate-limiter state.

      Returns {
          requestsInWindow: number;
          maxRequests: number;
          remainingRequests: number;
          windowMs: number;
          resetTime: number | null;
          canMakeRequest: boolean;
      }

      requestsInWindow, remainingRequests, canMakeRequest, resetTime (epoch ms when the oldest tracked request leaves the window — null when no requests are tracked).

    • Discard all tracked request timestamps. Useful in tests or after a clock jump. Not normally called in production.

      Returns void