Repository: discordjs/discord.js
File: packages/rest/src/lib/handlers/SequentialHandler.ts (TypeScript)

Code before:
	 * @param requestData - Extra data from the user's request needed for errors and additional processing
	 * @param retries - The number of retries this request has already attempted (recursion)
	 */
	private async runRequest(
		routeId: RouteData,
		url: string,
		options: RequestInit,
		requestData: HandlerRequestData,
		retries = 0,
	): Promise<ResponseLike> {
		/*
		 * After calculations have been done, pre-emptively stop further requests
		 * Potentially loop until this task can run if e.g. the global rate limit is hit twice
		 */
		while (this.limited) {
			const isGlobal = this.globalLimited;
			let limit: number;
			let timeout: number;
			let delay: Promise<void>;

			if (isGlobal) {
				const offset = normalizeRateLimitOffset(this.manager.options.offset, routeId.bucketRoute);

				// Set RateLimitData based on the global limit
				limit = this.manager.options.globalRequestsPerSecond;
				timeout = offset - Date.now();
				// If this is the first task to reach the global timeout, set the global delay
				if (!this.manager.globalDelay) {
					// The global delay function clears the global delay state when it is resolved
					this.manager.globalDelay = this.globalDelayFor(timeout);
				}

				delay = this.manager.globalDelay;
			} else {
				// Set RateLimitData based on the route-specific limit
				limit = this.limit;
				timeout = this.getTimeToReset(routeId);
				delay = sleep(timeout);
			}

			const rateLimitData: RateLimitData = {
				global: isGlobal,
				method: options.method ?? 'get',
				url,
				route: routeId.bucketRoute,
				majorParameter: this.majorParameter,
				hash: this.hash,
				limit,
				timeToReset: timeout,
				retryAfter: timeout,
				sublimitTimeout: 0,

Review comment (suggestion):
```suggestion
				timeout = this.manager.globalReset + offset - Date.now();
```

You removed a bit too much. 👋 Global ratelimit

Code after:
	 * @param requestData - Extra data from the user's request needed for errors and additional processing
	 * @param retries - The number of retries this request has already attempted (recursion)
	 */
	private async runRequest(
		routeId: RouteData,
		url: string,
		options: RequestInit,
		requestData: HandlerRequestData,
		retries = 0,
	): Promise<ResponseLike> {
		/*
		 * After calculations have been done, pre-emptively stop further requests
		 * Potentially loop until this task can run if e.g. the global rate limit is hit twice
		 */
		while (this.limited) {
			const isGlobal = this.globalLimited;
			let limit: number;
			let timeout: number;
			let delay: Promise<void>;

			if (isGlobal) {
				const offset = normalizeRateLimitOffset(this.manager.options.offset, routeId.bucketRoute);

				// Set RateLimitData based on the global limit
				limit = this.manager.options.globalRequestsPerSecond;
				timeout = this.manager.globalReset + offset - Date.now();
				// If this is the first task to reach the global timeout, set the global delay
				if (!this.manager.globalDelay) {
					// The global delay function clears the global delay state when it is resolved
					this.manager.globalDelay = this.globalDelayFor(timeout);
				}

				delay = this.manager.globalDelay;
			} else {
				// Set RateLimitData based on the route-specific limit
				limit = this.limit;
				timeout = this.getTimeToReset(routeId);
				delay = sleep(timeout);
			}

			const rateLimitData: RateLimitData = {
				global: isGlobal,
				method: options.method ?? 'get',
				url,
				route: routeId.bucketRoute,
				majorParameter: this.majorParameter,
				hash: this.hash,
				limit,
				timeToReset: timeout,
				retryAfter: timeout,
				sublimitTimeout: 0,