fix: make ratelimit timeout require event loop to be active (#8779)

* fix issue with ratelimits not working correctly

related to #8757

The ``ref`` option doesn't require the Node.js event loop to remain active when waiting for the timeout causing the program to end if there isn't an active gateway connection.

* Update packages/rest/src/lib/handlers/SequentialHandler.ts

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* Update packages/rest/src/lib/handlers/SequentialHandler.ts

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
hackermon
2022-10-23 06:45:02 -04:00
committed by GitHub
parent b2658ce504
commit 68d5712dea

View File

@@ -137,7 +137,7 @@ export class SequentialHandler implements IHandler {
* @param time - The amount of time to delay all requests for
*/
private async globalDelayFor(time: number): Promise<void> {
await sleep(time, undefined, { ref: false });
await sleep(time);
this.manager.globalDelay = null;
}
@@ -460,7 +460,7 @@ export class SequentialHandler implements IHandler {
this.#sublimitPromise?.resolve();
this.#sublimitPromise = null;
await sleep(sublimitTimeout, undefined, { ref: false });
await sleep(sublimitTimeout);
let resolve: () => void;
// eslint-disable-next-line promise/param-names, no-promise-executor-return
const promise = new Promise<void>((res) => (resolve = res));