smarter sharding™ (#732)

This commit is contained in:
Gus Caplan
2016-09-23 15:43:16 -05:00
committed by Amish Shah
parent fc9d049cc1
commit 063be5cee2
4 changed files with 18 additions and 12 deletions

View File

@@ -69,13 +69,8 @@ class ShardingManager extends EventEmitter {
* @param {number} [amount=this.totalShards] Number of shards to spawn
* @param {number} [delay=5500] How long to wait in between spawning each shard (in milliseconds)
*/
spawn(amount, delay = 5500) {
if (typeof amount !== 'undefined') {
if (typeof amount !== 'number' || isNaN(amount)) throw new TypeError('Amount of shards must be a number.');
if (amount < 1) throw new RangeError('Amount of shards must be at least 1.');
this.totalShards = amount;
}
spawn(amount = this.totalShards, delay = 5500) {
this.totalShards = amount;
this.createShard();
const interval = setInterval(() => {
if (this.shards.size === this.totalShards) clearInterval(interval);