Constructor
new ShardClientUtil(client, mode)
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | Client of the current shard |
mode |
ShardingManagerMode | Mode the shard was spawned with |
- Source:
Members
client :Client
Client for the shard
Type:
- Source:
(readonly) count :number
Total number of shards
Type:
- number
- Source:
(readonly) ids :Array.<number>
Array of shard IDs of this client
Type:
- Array.<number>
- Source:
mode :ShardingManagerMode
Mode the shard was spawned with
Type:
- Source:
(nullable) parentPort :MessagePort
Message port for the master process (only when ShardClientUtil#mode is `worker`)
Type:
- MessagePort
- Source:
Methods
(static) singleton(client, mode) → {ShardClientUtil}
Creates/gets the singleton of this class.
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | The client to use |
mode |
ShardingManagerMode | Mode the shard was spawned with |
- Source:
Returns:
- Type
- ShardClientUtil
(private) _handleMessage(message)
Handles an IPC message.
Parameters:
Name | Type | Description |
---|---|---|
message |
* | Message received |
- Source:
(private) _respond(type, message)
Sends a message to the master process, emitting an error from the client upon failure.
Parameters:
Name | Type | Description |
---|---|---|
type |
string | Type of response to send |
message |
* | Message to send |
- Source:
broadcastEval(script) → {Promise.<Array.<*>>}
Evaluates a script or function on all shards, in the context of the Clients.
Parameters:
Name | Type | Description |
---|---|---|
script |
string | function | JavaScript to run on each shard |
- Source:
- See:
Returns:
Results of the script execution
- Type
- Promise.<Array.<*>>
Example
client.shard.broadcastEval('this.guilds.cache.size')
.then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
.catch(console.error);
fetchClientValues(prop) → {Promise.<Array.<*>>}
Fetches a client property value of each shard.
Parameters:
Name | Type | Description |
---|---|---|
prop |
string | Name of the client property to get, using periods for nesting |
Returns:
- Type
- Promise.<Array.<*>>
Example
client.shard.fetchClientValues('guilds.cache.size')
.then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
.catch(console.error);
respawnAll(shardDelayopt, respawnDelayopt, spawnTimeoutopt) → {Promise.<void>}
Requests a respawn of all shards.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
shardDelay |
number |
<optional> |
5000 | How long to wait between shards (in milliseconds) |
respawnDelay |
number |
<optional> |
500 | How long to wait between killing a shard's process/worker and restarting it (in milliseconds) |
spawnTimeout |
number |
<optional> |
30000 | The amount in milliseconds to wait for a shard to become ready before continuing to another. (-1 or Infinity for no wait) |
- Source:
- See:
Returns:
Resolves upon the message being sent
- Type
- Promise.<void>
send(message) → {Promise.<void>}
Sends a message to the master process.
Parameters:
Name | Type | Description |
---|---|---|
message |
* | Message to send |
- Source:
Fires:
Returns:
- Type
- Promise.<void>