Constructor
new Shard(manager, id)
Parameters:
Name | Type | Description |
---|---|---|
manager |
ShardingManager | Manager that is creating this shard |
id |
number | ID of this shard |
- Source:
Extends
- EventEmitter
Members
(private) _evals :Map.<string, Promise>
Ongoing promises for calls to Shard#eval, mapped by the `script` they were called with
Type:
- Map.<string, Promise>
- Source:
(private) _exitListener :function
Listener function for the ChildProcess' `exit` event
Type:
- function
- Source:
(private) _fetches :Map.<string, Promise>
Ongoing promises for calls to Shard#fetchClientValue, mapped by the `prop` they were called with
Type:
- Map.<string, Promise>
- Source:
args :Array.<string>
Arguments for the shard's process (only when ShardingManager#mode is `process`)
Type:
- Array.<string>
- Source:
env :Object
Environment variables for the shard's process, or workerData for the shard's worker
Type:
- Object
- Source:
(nullable) execArgv :Array.<string>
Arguments for the shard's process executable (only when ShardingManager#mode is `process`)
Type:
- Array.<string>
- Source:
id :number
ID of the shard in the manager
Type:
- number
- Source:
manager :ShardingManager
Manager that created the shard
Type:
- Source:
(nullable) process :ChildProcess
Process of the shard (if ShardingManager#mode is `process`)
Type:
- ChildProcess
- Source:
ready :boolean
Whether the shard's Client is ready
Type:
- boolean
- Source:
(nullable) worker :Worker
Worker of the shard (if ShardingManager#mode is `worker`)
Type:
- Worker
- Source:
Methods
(private) _handleExit(respawnopt)
Handles the shard's process/worker exiting.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
respawn |
boolean |
<optional> |
this.manager.respawn | Whether to spawn the shard again |
- Source:
(private) _handleMessage(message)
Handles a message received from the child process/worker.
Parameters:
Name | Type | Description |
---|---|---|
message |
* | Message received |
- Source:
eval(script) → {Promise.<*>}
Evaluates a script or function on the shard, in the context of the Client.
Parameters:
Name | Type | Description |
---|---|---|
script |
string | function | JavaScript to run on the shard |
- Source:
Returns:
Result of the script execution
- Type
- Promise.<*>
fetchClientValue(prop) → {Promise.<*>}
Fetches a client property value of the shard.
Parameters:
Name | Type | Description |
---|---|---|
prop |
string | Name of the client property to get, using periods for nesting |
- Source:
Returns:
- Type
- Promise.<*>
Example
shard.fetchClientValue('guilds.cache.size')
.then(count => console.log(`${count} guilds in shard ${shard.id}`))
.catch(console.error);
kill()
Immediately kills the shard's process/worker and does not restart it.
- Source:
(async) respawn(delayopt, spawnTimeoutopt) → {Promise.<ChildProcess>}
Kills and restarts the shard's process/worker.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
delay |
number |
<optional> |
500 | How long to wait between killing the process/worker and restarting it (in milliseconds) |
spawnTimeout |
number |
<optional> |
30000 | The amount in milliseconds to wait until the Client has become ready before resolving. (-1 or Infinity for no wait) |
- Source:
Returns:
- Type
- Promise.<ChildProcess>
send(message) → {Promise.<Shard>}
Sends a message to the shard's process/worker.
Parameters:
Name | Type | Description |
---|---|---|
message |
* | Message to send to the shard |
- Source:
Returns:
- Type
- Promise.<Shard>
(async) spawn(spawnTimeoutopt) → {Promise.<ChildProcess>}
Forks a child process or creates a worker thread for the shard.
You should not need to call this manually.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
spawnTimeout |
number |
<optional> |
30000 | The amount in milliseconds to wait until the Client has become ready before resolving. (-1 or Infinity for no wait) |
- Source:
Returns:
- Type
- Promise.<ChildProcess>
Events
death
Emitted upon the shard's child process/worker exiting.
Parameters:
Name | Type | Description |
---|---|---|
process |
ChildProcess | Worker | Child process/worker that exited |
- Source:
disconnect
Emitted upon the shard's Client#disconnect event.
- Source:
message
Emitted upon receiving a message from the child process/worker.
Parameters:
Name | Type | Description |
---|---|---|
message |
* | Message that was received |
- Source:
ready
Emitted upon the shard's Client#ready event.
- Source:
reconnecting
Emitted upon the shard's Client#reconnecting event.
- Source:
spawn
Emitted upon the creation of the shard's child process/worker.
Parameters:
Name | Type | Description |
---|---|---|
process |
ChildProcess | Worker | Child process/worker that was created |
- Source: