Skip to content

dependabit / github-client/src / RateLimitHandler

Class: RateLimitHandler

Defined in: packages/github-client/src/rate-limit.ts:101

Manages GitHub API rate limits and provides budget-reservation utilities for batch operations.

Remarks

Use RateLimitHandler.reserveBudget before starting a batch of API calls to verify that sufficient quota exists. Use RateLimitHandler.waitIfNeeded as a simpler "wait until safe" primitive.

Use When

Coordinating large batches of GitHub API calls (e.g., checking 100+ dependencies in one monitor run) where you need pre-flight quota checks.

Avoid When

Making a small number of one-off API calls — use GitHubClient with its built-in threshold check instead.

Pitfalls

  • reserveBudget does not lock the quota — another process could consume the reserved capacity between the check and the actual calls.
  • The handler does not track the search or GraphQL categories individually for budget reservation; use getRateLimitStatus to inspect those limits manually.

Constructors

Constructor

ts
new RateLimitHandler(auth?): RateLimitHandler;

Defined in: packages/github-client/src/rate-limit.ts:106

Parameters

ParameterType
auth?string

Returns

RateLimitHandler

Methods

calculateWaitTime()

ts
calculateWaitTime(rateLimitInfo): number;

Defined in: packages/github-client/src/rate-limit.ts:152

Calculates wait time until rate limit resets

Parameters

ParameterType
rateLimitInfoRateLimitInfo

Returns

number


canProceed()

ts
canProceed(estimatedCalls, options?): Promise<{
  canProceed: boolean;
  reason?: string;
}>;

Defined in: packages/github-client/src/rate-limit.ts:206

Proactively check if operation can proceed without hitting rate limit

Parameters

ParameterType
estimatedCallsnumber
options?{ safetyMargin?: number; threshold?: number; }
options.safetyMargin?number
options.threshold?number

Returns

Promise<{ canProceed: boolean; reason?: string; }>


checkRateLimit()

ts
checkRateLimit(): Promise<RateLimitInfo>;

Defined in: packages/github-client/src/rate-limit.ts:115

Checks current rate limit status

Returns

Promise<RateLimitInfo>


getCachedStatus()

ts
getCachedStatus(): RateLimitStatus | undefined;

Defined in: packages/github-client/src/rate-limit.ts:273

Gets cached rate limit status (avoids API call)

Returns

RateLimitStatus | undefined


getRateLimitStatus()

ts
getRateLimitStatus(): Promise<RateLimitStatus>;

Defined in: packages/github-client/src/rate-limit.ts:241

Gets detailed rate limit status for all API categories

Returns

Promise<RateLimitStatus>


reserveBudget()

ts
reserveBudget(callsNeeded, options?): Promise<BudgetReservation>;

Defined in: packages/github-client/src/rate-limit.ts:167

Attempts to reserve API call budget with proactive checking

Parameters

ParameterType
callsNeedednumber
options?{ maxWaitTime?: number; safetyMargin?: number; }
options.maxWaitTime?number
options.safetyMargin?number

Returns

Promise<BudgetReservation>


waitIfNeeded()

ts
waitIfNeeded(): Promise<void>;

Defined in: packages/github-client/src/rate-limit.ts:137

Waits if rate limited

Returns

Promise<void>

Released under the MIT License.