Add client shard eval/client property fetching, and improve existing shard stuff

This commit is contained in:
Schuyler Cebulskie
2016-09-27 02:19:53 -04:00
parent c26fc49caf
commit e5a987e0ef
7 changed files with 177 additions and 71 deletions

View File

@@ -41,6 +41,10 @@ class ShardingManager extends EventEmitter {
if (totalShards < 1) throw new RangeError('Amount of shards must be at least 1.');
if (totalShards !== Math.floor(totalShards)) throw new RangeError('Amount of shards must be an integer.');
/**
* Whether shards should automatically respawn upon exiting
* @type {boolean}
*/
this.respawn = respawn;
/**
@@ -48,6 +52,19 @@ class ShardingManager extends EventEmitter {
* @type {Collection<number, Shard>}
*/
this.shards = new Collection();
this.on('message', (shard, message) => {
if (!message) return;
if (message._sEval) {
this.broadcastEval(message._sEval)
.then(results => shard.send({ _sEval: message._sEval, _result: results }))
.catch(err => shard.send({ _sEval: message._sEval, _error: err }));
} else if (message._sFetchProp) {
this.fetchClientValues(message._sFetchProp)
.then(results => shard.send({ _sFetchProp: message._sFetchProp, _result: results }))
.catch(err => shard.send({ _sFetchProp: message._sFetchProp, _error: err }));
}
});
}
/**