mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
refactor(rest): separate functions into diff files (#685)
* shtufffff * fixe rate limit path infinite loop * refactor * ID > id * Update process_request_headers.ts * file names Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> Co-authored-by: ayntee <ayyantee@gmail.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { rest } from "./rest.ts";
|
||||
|
||||
/** This will create a infinite loop running in 1 seconds using tail recursion to keep rate limits clean. When a rate limit resets, this will remove it so the queue can proceed. */
|
||||
export function processRateLimitedPaths() {
|
||||
const now = Date.now();
|
||||
|
||||
rest.ratelimitedPaths.forEach((value, key) => {
|
||||
// IF THE TIME HAS NOT REACHED CANCEL
|
||||
if (value.resetTimestamp > now) return;
|
||||
// RATE LIMIT IS OVER, DELETE THE RATE LIMITER
|
||||
rest.ratelimitedPaths.delete(key);
|
||||
// IF IT WAS GLOBAL ALSO MARK THE GLOBAL VALUE AS FALSE
|
||||
if (key === "global") rest.globallyRateLimited = false;
|
||||
});
|
||||
|
||||
// ALL PATHS ARE CLEARED CAN CANCEL OUT!
|
||||
if (!rest.ratelimitedPaths.size) {
|
||||
rest.processingRateLimitedPaths = false;
|
||||
return;
|
||||
} else {
|
||||
rest.processingRateLimitedPaths = true;
|
||||
// RECHECK IN 1 SECOND
|
||||
setTimeout(() => processRateLimitedPaths(), 1000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user