Worker

worker~ Worker

Worker implementation. Warning!!! All defined workers MUST be terminated until application shut down. In opposit case you can get AV.

Constructor

new Worker(paramsObj)

Arguments:
  1. paramsObj (Object)  Parameters object
    Properties
    1. onmessage (String|function)  Message handler. Accept 1 parameter - message
    2. onterminate (String|function)  Terminate handler. Accept no parameters
    3. onerror (String|function)  Error handler. Accept 2 parameters - message and exception
    4. message   Message. If assigned then post this message after start thread

Methods

getMessage() → *

Get message from the worker thread

waitMessage(timeout, checkEveryMSopt) → *

Try get message from worker thread. Wait until message received or timeout expired
Arguments:
  1. timeout (Number)  Timeout in milliseconds
  2. [checkEveryMS=10] (Number)  Sleep duration before next try get message

terminate()

Terminate worker thread

postMessage(message)

Post message to worker thread. Message are stringified before send
Arguments:
  1. message (*)