mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
reducing complexity
This commit is contained in:
+5
-9
@@ -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. */
|
||||
|
||||
@@ -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[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user