MCPcopy
hub / github.com/cursor/community-plugins / respectRateLimit

Function respectRateLimit

apps/cursor/src/scripts/extract-from-github.ts:113–124  ·  view source on GitHub ↗

Sleep until the GitHub Search rate-limit resets if we're nearly empty.

(res: Response, label: string)

Source from the content-addressed store, hash-verified

111
112/** Sleep until the GitHub Search rate-limit resets if we're nearly empty. */
113async function respectRateLimit(res: Response, label: string) {
114 const remaining = Number(res.headers.get("x-ratelimit-remaining") ?? "30");
115 if (remaining > 1) return;
116 const reset = Number(res.headers.get("x-ratelimit-reset") ?? "0") * 1000;
117 const wait = Math.max(reset - Date.now(), 0) + 1000;
118 if (wait > 0) {
119 console.warn(
120 ` ${label}: rate budget exhausted (remaining=${remaining}), sleeping ${Math.ceil(wait / 1000)}s`,
121 );
122 await sleep(wait);
123 }
124}
125
126async function githubSearch<T>(
127 endpoint: "code" | "repositories",

Callers 1

githubSearchFunction · 0.85

Calls 1

sleepFunction · 0.70

Tested by

no test coverage detected