reducing complexity

This commit is contained in:
Skillz
2021-02-22 14:31:03 -05:00
parent 98690a037e
commit 4f8d5a4b65
2 changed files with 9 additions and 20 deletions
+5 -9
View File
@@ -1,7 +1,7 @@
import { BASE_URL, USER_AGENT } from "../util/constants.ts";
import { restCache } from "./cache.ts";
import { ServerRequest } from "./deps.ts";
import { startQueue } from "./queue.ts";
import { processQueue } from "./queue.ts";
import {
QueuedRequest,
RestServerOptions,
@@ -30,20 +30,16 @@ export function processRequest(
const queue = restCache.pathQueues.get(id);
// IF THE QUEUE EXISTS JUST ADD THIS TO THE QUEUE
if (queue) {
queue.requests.push({ request, payload, options });
queue.push({ request, payload, options });
} else {
// CREATES A NEW QUEUE
restCache.pathQueues.set(id, {
processing: false,
requests: [{
restCache.pathQueues.set(id, [{
request,
payload,
options,
}],
});
}]);
processQueue(id);
}
startQueue();
}
/** Creates the request body and headers that are necessary to send a request. Will handle different types of methods and everything necessary for discord. */
+1 -8
View File
@@ -3,7 +3,7 @@ import { RestEventHandlers } from "./server.ts";
export interface RestCache {
/** The queues that are currently needing to be executed. Key is the url path and the value is all the requests in this same path. Paths are mapped by MAJOR params. */
pathQueues: Map<string, Queue>;
pathQueues: Map<string, QueuedRequest[]>;
/** Whether or not the queues are currently processing. */
processingQueue: boolean;
/** Whether or not this token has been globally rate limited. */
@@ -13,10 +13,3 @@ export interface RestCache {
/** The event handlers are functions that run when something is happening internally. Users can customize this for analytics, debugging, logging or anything their heart desires. */
eventHandlers: RestEventHandlers;
}
export interface Queue {
/** Whether or not this queue is being processed */
processing: boolean;
/** All the requests in this queue. */
requests: QueuedRequest[];
}