Worker

@unitybase/base/worker~ Worker

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

Constructor

new Worker(paramsObj)

Arguments:
  1. paramsObj (Object|Number)  Parameters object for create new Worker or WorkerID for use existing Worker
    Properties
    1. [name='Worker'] (String)  Name of Worker for debugger
    2. onmessage (String|function)  Message handler. Accept 1 parameter - message
    3. onterminate (String|function)  Terminate handler. Accept no parameters
    4. onerror (String|function)  Error handler. Accept 2 parameters - message and exception
    5. 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 (*)