Constructor
new Worker(file)
Create a worker.
Extends:
- EventEmitter
Parameters:
Name | Type | Description |
---|---|---|
file |
String |
- Source:
Extends
- EventEmitter
Methods
(private) _execute(packet, timeout, resolve, reject)
Call a method for a worker to execute.
Parameters:
Name | Type | Description |
---|---|---|
packet |
Packet | |
timeout |
Number | |
resolve |
function | |
reject |
function | the worker method specifies. |
- Source:
destroy()
Destroy the worker.
- Source:
execute(packet, timeout) → {Promise}
Call a method for a worker to execute.
Parameters:
Name | Type | Description |
---|---|---|
packet |
Packet | |
timeout |
Number |
- Source:
Returns:
- Type
- Promise
(private) handlePacket(packet)
Handle packet.
Parameters:
Name | Type | Description |
---|---|---|
packet |
Packet |
- Source:
(private) init()
Initialize worker. Bind to events.
- Source:
killJobs()
Kill all jobs associated with worker.
- Source:
(private) listen()
Listen for packets.
- Source:
rejectJob(id, err)
Reject a job.
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | |
err |
Error |
- Source:
resolveJob(id, result)
Resolve a job.
Parameters:
Name | Type | Description |
---|---|---|
id |
Number | |
result |
Packet |
- Source:
send(packet) → {Boolean}
Frame and send a packet.
Parameters:
Name | Type | Description |
---|---|---|
packet |
Packet |
- Source:
Returns:
- Type
- Boolean
sendEnv(env) → {Boolean}
Send environment.
Parameters:
Name | Type | Description |
---|---|---|
env |
Object |
- Source:
Returns:
- Type
- Boolean
sendEvent(event, …arg) → {Boolean}
Emit an event on the worker side.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
event |
String | ||
arg |
Object |
<repeatable> |
- Source:
Returns:
- Type
- Boolean
write(data) → {Boolean}
Send data to worker.
Parameters:
Name | Type | Description |
---|---|---|
data |
Buffer |
- Source:
Returns:
- Type
- Boolean