Help Center

Local Navigation

Object: Worker

Availability

BlackBerry® Device Software version 6.0 or later

The Worker object represents a thread to be run in the background.

Web workers work as follows:

  1. On the parent web page, a script runs in the main thread of the Window object.
  2. The script in the main thread spawns a new thread by constructing a new Worker object. The constructor takes as an argument the JavaScript file that it is to load and execute.
  3. The worker executes the script.

To create a new worker thread, you need only construct a new worker object with the JavaScript file it is to load as the argument. For example:

var worker = new Worker(workerScript.js)

Worker event handlers

Property name

Type

Description

Status

Availability

onerror

EventListener

Specifies the function to perform when an ErrorEvent occurs in the worker thread.

writable

6.0 or later

onmessage

EventListener

Specifies the function to perform when a MessageEvent occurs in the worker thread.

writable

6.0 or later

Worker methods

Method name

Description

Support level

Availability

postMessage()

Sends a message to the worker thread. The message contains the data to be passed between threads.

HTML 5

6.0 or later

terminate()

Terminates the worker.

HTML 5

6.0 or later

Next topic: Traversal API
Previous topic: Thread API

Was this information helpful? Send us your comments.