document sharding stuff

This commit is contained in:
Amish Shah
2016-09-04 12:27:01 +01:00
parent b1a25bd176
commit f23c07a08e
3 changed files with 24 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@@ -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;

View File

@@ -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);
}
}