mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
remove queue
This commit is contained in:
@@ -1,2 +1 @@
|
|||||||
export { decompress_with as decompressWith } from "https://unpkg.com/@evan/wasm@0.0.40/target/zlib/deno.js";
|
export { decompress_with as decompressWith } from "https://unpkg.com/@evan/wasm@0.0.40/target/zlib/deno.js";
|
||||||
export { default as Queue } from "https://esm.sh/denque@1.5.0";
|
|
||||||
|
|||||||
+8
-34
@@ -1,7 +1,6 @@
|
|||||||
import { getGatewayBot } from "../../api/handlers/gateway.ts";
|
import { getGatewayBot } from "../../api/handlers/gateway.ts";
|
||||||
import { Intents } from "../../types/options.ts";
|
import { Intents } from "../../types/options.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../../util/collection.ts";
|
||||||
import { Queue } from "./deps.ts";
|
|
||||||
import { ws } from "./ws.ts";
|
import { ws } from "./ws.ts";
|
||||||
|
|
||||||
/** ADVANCED DEVS ONLY!!!!!!
|
/** ADVANCED DEVS ONLY!!!!!!
|
||||||
@@ -48,8 +47,8 @@ export async function startGateway(options: StartGatewayOptions) {
|
|||||||
* TODO: Put in a queue system and support clustering
|
* TODO: Put in a queue system and support clustering
|
||||||
*/
|
*/
|
||||||
export function spawnShards(shardID: number) {
|
export function spawnShards(shardID: number) {
|
||||||
/** Stored as bucketID: [clusterID, Queue[ShardIDs]] */
|
/** Stored as bucketID: [clusterID, [ShardIDs]] */
|
||||||
const buckets = new Collection<number, [number, Queue][]>();
|
const buckets = new Collection<number, number[][]>();
|
||||||
const maxShards = ws.maxShards || ws.botGatewayData.shards;
|
const maxShards = ws.maxShards || ws.botGatewayData.shards;
|
||||||
let cluster = 0;
|
let cluster = 0;
|
||||||
|
|
||||||
@@ -64,11 +63,8 @@ export function spawnShards(shardID: number) {
|
|||||||
const bucket = buckets.get(bucketID);
|
const bucket = buckets.get(bucketID);
|
||||||
|
|
||||||
if (!bucket) {
|
if (!bucket) {
|
||||||
const queue = new Queue();
|
|
||||||
queue.push(i);
|
|
||||||
|
|
||||||
// Create the bucket since it doesnt exist
|
// Create the bucket since it doesnt exist
|
||||||
buckets.set(bucketID, [[cluster, queue]]);
|
buckets.set(bucketID, [[cluster, i]]);
|
||||||
|
|
||||||
if (cluster + 1 <= ws.maxClusters) cluster++;
|
if (cluster + 1 <= ws.maxClusters) cluster++;
|
||||||
else {
|
else {
|
||||||
@@ -76,17 +72,14 @@ export function spawnShards(shardID: number) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// FIND A QUEUE IN THIS BUCKET THAT HAS SPACE
|
// FIND A QUEUE IN THIS BUCKET THAT HAS SPACE
|
||||||
const queue = bucket.find((q) => q[1].length < ws.shardsPerCluster + 1);
|
const queue = bucket.find((q) => q.length < ws.shardsPerCluster + 1);
|
||||||
if (queue) {
|
if (queue) {
|
||||||
// IF THE QUEUE HAS SPACE JUST ADD IT TO THIS QUEUE
|
// IF THE QUEUE HAS SPACE JUST ADD IT TO THIS QUEUE
|
||||||
queue[1].push(i);
|
queue.push(i);
|
||||||
} else {
|
} else {
|
||||||
const newQueue = new Queue();
|
|
||||||
newQueue.push(i);
|
|
||||||
|
|
||||||
if (cluster + 1 <= ws.maxClusters) cluster++;
|
if (cluster + 1 <= ws.maxClusters) cluster++;
|
||||||
// ADD A NEW QUEUE FOR THIS SHARD
|
// ADD A NEW QUEUE FOR THIS SHARD
|
||||||
bucket.push([cluster, newQueue]);
|
bucket.push([cluster, i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +87,7 @@ export function spawnShards(shardID: number) {
|
|||||||
|
|
||||||
// SPREAD THIS OUT TO DIFFERENT CLUSTERS TO BEGIN STARTING UP
|
// SPREAD THIS OUT TO DIFFERENT CLUSTERS TO BEGIN STARTING UP
|
||||||
buckets.forEach(async (bucket, bucketID) => {
|
buckets.forEach(async (bucket, bucketID) => {
|
||||||
for (const [clusterID, queue] of bucket) {
|
for (const [clusterID, ...queue] of bucket) {
|
||||||
let shardID = queue.shift();
|
let shardID = queue.shift();
|
||||||
|
|
||||||
while (shardID !== undefined) {
|
while (shardID !== undefined) {
|
||||||
@@ -103,26 +96,6 @@ export function spawnShards(shardID: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// let skipChecks = 0;
|
|
||||||
|
|
||||||
// while (shardID <= ws.lastShardID) {
|
|
||||||
// if (skipChecks) {
|
|
||||||
// // Start The shard
|
|
||||||
// ws.identify(shardID, ws.maxShards);
|
|
||||||
|
|
||||||
// shardID++;
|
|
||||||
// skipChecks--;
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Previous shards is still not fully ready.
|
|
||||||
// if (!ws.createNextShard) continue;
|
|
||||||
|
|
||||||
// // Allows next iteration to create shard
|
|
||||||
// ws.createNextShard = false;
|
|
||||||
// // Set the amount of shards to start up be the bots max concurrency limit
|
|
||||||
// skipChecks = ws.botGatewayData.sessionStartLimit.maxConcurrency;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Allows users to hook in and change to communicate to different clusters across different servers or anything they like. For example using redis pubsub to talk to other servers. */
|
/** Allows users to hook in and change to communicate to different clusters across different servers or anything they like. For example using redis pubsub to talk to other servers. */
|
||||||
@@ -131,6 +104,7 @@ export async function tellClusterToIdentify(
|
|||||||
shardID: number,
|
shardID: number,
|
||||||
bucketID: number,
|
bucketID: number,
|
||||||
) {
|
) {
|
||||||
|
// TODO: resolve promise 5 sec after ready
|
||||||
await ws.identify(shardID, ws.maxShards);
|
await ws.identify(shardID, ws.maxShards);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user