mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
refactor(Sharding): use options objects (#5510)
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
@@ -161,13 +161,13 @@ class ShardingManager extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Spawns multiple shards.
|
||||
* @param {number|string} [amount=this.totalShards] Number of shards to spawn
|
||||
* @param {number} [delay=5500] How long to wait in between spawning each shard (in milliseconds)
|
||||
* @param {number} [spawnTimeout=30000] The amount in milliseconds to wait until the {@link Client} has become ready
|
||||
* before resolving. (-1 or Infinity for no wait)
|
||||
* @param {Object} [options] Options for spawning shards
|
||||
* @param {number|string} [options.amount=this.totalShards] Number of shards to spawn
|
||||
* @param {number} [options.delay=5500] How long to wait in between spawning each shard (in milliseconds)
|
||||
* @param {number} [options.timeout=30000] The amount in milliseconds to wait until the {@link Client} has become
|
||||
* @returns {Promise<Collection<number, Shard>>}
|
||||
*/
|
||||
async spawn(amount = this.totalShards, delay = 5500, spawnTimeout) {
|
||||
async spawn({ amount = this.totalShards, delay = 5500, timeout = 30000 } = {}) {
|
||||
// Obtain/verify the number of shards to spawn
|
||||
if (amount === 'auto') {
|
||||
amount = await Util.fetchRecommendedShards(this.token);
|
||||
@@ -202,7 +202,7 @@ class ShardingManager extends EventEmitter {
|
||||
for (const shardID of this.shardList) {
|
||||
const promises = [];
|
||||
const shard = this.createShard(shardID);
|
||||
promises.push(shard.spawn(spawnTimeout));
|
||||
promises.push(shard.spawn(timeout));
|
||||
if (delay > 0 && this.shards.size !== this.shardList.length) promises.push(Util.delayFor(delay));
|
||||
await Promise.all(promises); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
@@ -270,17 +270,18 @@ class ShardingManager extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Kills all running shards and respawns them.
|
||||
* @param {number} [shardDelay=5000] How long to wait between shards (in milliseconds)
|
||||
* @param {number} [respawnDelay=500] How long to wait between killing a shard's process and restarting it
|
||||
* @param {Object} [options] Options for respawning shards
|
||||
* @param {number} [options.shardDelay=5000] How long to wait between shards (in milliseconds)
|
||||
* @param {number} [options.respawnDelay=500] How long to wait between killing a shard's process and restarting it
|
||||
* (in milliseconds)
|
||||
* @param {number} [spawnTimeout=30000] The amount in milliseconds to wait for a shard to become ready before
|
||||
* @param {number} [options.timeout=30000] The amount in milliseconds to wait for a shard to become ready before
|
||||
* continuing to another. (-1 or Infinity for no wait)
|
||||
* @returns {Promise<Collection<string, Shard>>}
|
||||
*/
|
||||
async respawnAll(shardDelay = 5000, respawnDelay = 500, spawnTimeout) {
|
||||
async respawnAll({ shardDelay = 5000, respawnDelay = 500, timeout = 30000 } = {}) {
|
||||
let s = 0;
|
||||
for (const shard of this.shards.values()) {
|
||||
const promises = [shard.respawn(respawnDelay, spawnTimeout)];
|
||||
const promises = [shard.respawn({ respawnDelay, timeout })];
|
||||
if (++s < this.shards.size && shardDelay > 0) promises.push(Util.delayFor(shardDelay));
|
||||
await Promise.all(promises); // eslint-disable-line no-await-in-loop
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user