mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
document sharding stuff
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,6 +1,9 @@
|
||||
const childProcess = require('child_process');
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* Represents a Shard spawned by the ShardingManager.
|
||||
*/
|
||||
class Shard {
|
||||
constructor(manager, id) {
|
||||
this.manager = manager;
|
||||
|
||||
@@ -1,17 +1,35 @@
|
||||
const childProcess = require('child_process');
|
||||
const path = require('path');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const Collection = require('../util/Collection');
|
||||
const Shard = require('./Shard');
|
||||
|
||||
/**
|
||||
* This is a utility class that can be used to help you spawn shards of your Client. Each shard is completely separate
|
||||
* from the other. The Shard Manager takes a path to a file and spawns it under the specified amount of shards safely.
|
||||
* <warn>The Sharding Manager is still experimental</warn>
|
||||
* @extends {EventEmitter}
|
||||
*/
|
||||
class ShardingManager extends EventEmitter {
|
||||
/**
|
||||
* Creates an instance of ShardingManager.
|
||||
* @param {string} file the path to your file
|
||||
* @param {number} totalShards the number of shards you would like to spawn
|
||||
*/
|
||||
constructor(file, totalShards) {
|
||||
super();
|
||||
this.file = file;
|
||||
if (!path.isAbsolute(file)) {
|
||||
this.file = path.resolve(`${process.cwd()}${file}`);
|
||||
}
|
||||
/**
|
||||
* The amount of shards that this manager is going to spawn
|
||||
* @type {number}
|
||||
*/
|
||||
this.totalShards = totalShards;
|
||||
/**
|
||||
* A collection of shards that this manager has spawned.
|
||||
* @type {Collection<number, Shard>}
|
||||
*/
|
||||
this.shards = new Collection();
|
||||
this.waiting = new Collection();
|
||||
}
|
||||
@@ -30,7 +48,7 @@ class ShardingManager extends EventEmitter {
|
||||
if (this.shards.size === this.totalShards) {
|
||||
return clearInterval(interval);
|
||||
}
|
||||
this.createShard();
|
||||
return this.createShard();
|
||||
}, 5500);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user