Add ShardingManager#send and ShardingManager#broadcast (#730)

* add ShardingManager#send and ShardingManager#broadcast

* make gawdl3y happy

* Fix a thing
This commit is contained in:
Gus Caplan
2016-09-22 20:35:08 -05:00
committed by Schuyler Cebulskie
parent e86b93b34f
commit edd174a5eb
2 changed files with 19 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -73,6 +73,24 @@ class ShardingManager extends EventEmitter {
else this.createShard();
}, 5500);
}
/**
* Sends a message to a shard by ID.
* @param {number} id ID of the shard to send the message to
* @param {*} message Message to send to the shard
*/
send(id, message) {
if (!this.shards.has(id)) throw new Error('Shard ID is invalid!');
this.shards.get(id).process.send(message);
}
/**
* Broadcast a message to all shards.
* @param {*} message Message to be sent to the shards
*/
broadcast(message) {
for (const shard of this.shards.values()) shard.process.send(message);
}
}
module.exports = ShardingManager;