Class: WorkerPool

workers~WorkerPool(options)

Worker Pool

Constructor

new WorkerPool(options)

Create a worker pool.

Extends:
  • EventEmitter
Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
size Number <optional>
num-cores

Max pool size.

timeout Number <optional>
120000

Execution timeout.

Properties:
Name Type Description
size Number
timeout Number
children Map
uid Number
Source:

Extends

  • EventEmitter

Methods

alloc() → {Worker}

Allocate a new worker, will not go above size option and will automatically load balance the workers.

Source:
Returns:
Type
Worker

(async) check(tx, view, flags) → {Promise}

Execute the tx check job (default timeout).

Parameters:
Name Type Description
tx TX
view CoinView
flags VerifyFlags
Source:
Returns:
Type
Promise

(async) checkInput(tx, index, coin, flags) → {Promise}

Execute the tx input check job (default timeout).

Parameters:
Name Type Description
tx TX
index Number
coin Coin | Output
flags VerifyFlags
Source:
Returns:
Type
Promise

(async) close() → {Promise}

Close worker pool.

Source:
Returns:
Type
Promise

destroy()

Destroy all workers.

Source:

(async) ecSign(msg, key) → {Promise}

Execute the secp256k1 signing job (no timeout).

Parameters:
Name Type Description
msg Buffer
key Buffer
Source:
Returns:
Type
Promise

(async) ecVerify(msg, sig, key) → {Promise}

Execute the secp256k1 verify job (no timeout).

Parameters:
Name Type Description
msg Buffer
sig Buffer

DER formatted.

key Buffer
Source:
Returns:
Type
Promise

execute(packet, timeout) → {Promise}

Call a method for a worker to execute.

Parameters:
Name Type Description
packet Packet
timeout Number
Source:
Returns:
Type
Promise

(async) mine(data, target, min, max) → {Promise}

Execute the mining job (no timeout).

Parameters:
Name Type Description
data Buffer
target Buffer
min Number
max Number
Source:
Returns:
  • Returns {Number}.
Type
Promise

(async) open() → {Promise}

Open worker pool.

Source:
Returns:
Type
Promise

(async) scrypt(passwd, salt, N, r, p, len) → {Promise}

Execute scrypt job (no timeout).

Parameters:
Name Type Description
passwd Buffer
salt Buffer
N Number
r Number
p Number
len Number
Source:
Returns:
Type
Promise

sendEvent(event, …arg) → {Boolean}

Emit an event on the worker side (all workers).

Parameters:
Name Type Attributes Description
event String
arg Object <repeatable>
Source:
Returns:
Type
Boolean

set(options)

Set worker pool options.

Parameters:
Name Type Description
options Object
Source:

(async) sign(tx, ring, type) → {Promise}

Execute the tx signing job (default timeout).

Parameters:
Name Type Description
tx MTX
ring Array.<KeyRing>
type SighashType
Source:
Returns:
Type
Promise

(async) signInput(tx, index, coin, ring, type) → {Promise}

Execute the tx input signing job (default timeout).

Parameters:
Name Type Description
tx MTX
index Number
coin Coin | Output
ring KeyRing
type SighashType
Source:
Returns:
Type
Promise

spawn(id) → {Worker}

Spawn a new worker.

Parameters:
Name Type Description
id Number

Worker ID.

Source:
Returns:
Type
Worker