mirror of
https://github.com/danbulant/discord.js
synced 2026-06-08 09:13:22 +00:00
document sharding stuff
This commit is contained in:
parent
b1a25bd176
commit
f23c07a08e
3 changed files with 24 additions and 3 deletions
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,9 @@
|
||||||
const childProcess = require('child_process');
|
const childProcess = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Shard spawned by the ShardingManager.
|
||||||
|
*/
|
||||||
class Shard {
|
class Shard {
|
||||||
constructor(manager, id) {
|
constructor(manager, id) {
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,35 @@
|
||||||
const childProcess = require('child_process');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const Collection = require('../util/Collection');
|
const Collection = require('../util/Collection');
|
||||||
const Shard = require('./Shard');
|
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 {
|
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) {
|
constructor(file, totalShards) {
|
||||||
super();
|
super();
|
||||||
this.file = file;
|
this.file = file;
|
||||||
if (!path.isAbsolute(file)) {
|
if (!path.isAbsolute(file)) {
|
||||||
this.file = path.resolve(`${process.cwd()}${file}`);
|
this.file = path.resolve(`${process.cwd()}${file}`);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* The amount of shards that this manager is going to spawn
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
this.totalShards = totalShards;
|
this.totalShards = totalShards;
|
||||||
|
/**
|
||||||
|
* A collection of shards that this manager has spawned.
|
||||||
|
* @type {Collection<number, Shard>}
|
||||||
|
*/
|
||||||
this.shards = new Collection();
|
this.shards = new Collection();
|
||||||
this.waiting = new Collection();
|
this.waiting = new Collection();
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +48,7 @@ class ShardingManager extends EventEmitter {
|
||||||
if (this.shards.size === this.totalShards) {
|
if (this.shards.size === this.totalShards) {
|
||||||
return clearInterval(interval);
|
return clearInterval(interval);
|
||||||
}
|
}
|
||||||
this.createShard();
|
return this.createShard();
|
||||||
}, 5500);
|
}, 5500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue