Constructor
new Cluster(manager, id, shardList, totalShards)
Name | Type | Description |
---|---|---|
manager | ClusterManager | Manager that is creating this cluster |
id | number | ID of this cluster |
shardList | ||
totalShards |
- Source
Extends
- EventEmitter
Members
args :Array.<string>
Arguments for the shard's process (only when ShardingManager#mode is process
)
- Array.<string>
- Source
env :object
Environment variables for the cluster's process, or workerData for the cluster's worker
- object
- Source
execArgv :Array.<string>
Arguments for the shard's process executable (only when ShardingManager#mode is process
)
- Array.<string>
- Source
id :number
ID of the cluster in the manager
- number
- Source
manager :ClusterManager
Manager that created the cluster
- Source
shardList :number
Internal Shards which will get spawned in the cluster
- number
- Source
thread :Child|Worker
Process of the cluster (if ClusterManager#mode is process
)
- Child | Worker
- Source
totalShards :number
the amount of real shards
- number
- Source
Methods
(async) eval(script, context, timeout) → {Promise.<*>}
Evaluates a script or function on the cluster, in the context of the Client.
Name | Type | Description |
---|---|---|
script | string | function | JavaScript to run on the cluster |
context | ||
timeout |
- Source
Result of the script execution
- Type:
- Promise.<*>
kill(options)
Immediately kills the clusters's process/worker and does not restart it.
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
options | object | Some Options for managing the Kill Properties
|
- Source
request(message) → {Promise.<*>}
Sends a Request to the ClusterClient and returns the reply
Name | Type | Description |
---|---|---|
message | Object | Message, which should be sent as request |
- Source
Reply of the Message
- Type:
- Promise.<*>
client.cluster.request({content: 'hello'})
.then(result => console.log(result)) //hi
.catch(console.error);
(async) respawn(optionsopt) → {Promise.<Child>}
Kills and restarts the cluster's process/worker.
Name | Type | Attributes | Description |
---|---|---|---|
options | ClusterRespawnOptions | <optional> | Options for respawning the cluster |
- Source
- Type:
- Promise.<Child>
send(message) → {Promise.<Shard>}
Sends a message to the cluster's process/worker.
Name | Type | Description |
---|---|---|
message | * | BaseMessage | Message to send to the cluster |
- Source
- Type:
- Promise.<Shard>
(async) spawn(spawnTimeoutopt) → {Promise.<Child>}
Forks a child process or creates a worker thread for the cluster.
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
- Type:
- Promise.<Child>
triggerMaintenance(reason)
Name | Type | Description |
---|---|---|
reason | string | If maintenance should be enabled with a given reason or disabled when nonce provided |
- Source
Events
death
Emitted upon the cluster's child process/worker exiting.
Name | Type | Description |
---|---|---|
process | Child | Worker | Child process/worker that exited |
- Source
error
Emitted upon the cluster's child process/worker error.
Name | Type | Description |
---|---|---|
process | Child | Worker | Child process/worker, where error occurred |
- Source
ready
Emitted upon the cluster's Client#ready event.
- Source
spawn
Emitted upon the creation of the cluster's child process/worker.
Name | Type | Description |
---|---|---|
process | Child | Worker | Child process/worker that was created |
- Source