JavaScript Reference

Local Navigation

Thread API

Object

Description

Availability

Worker

Represents a new thread.

6.0 or later

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)

Back To Top

Worker event handlers

Property name

Type

Description

Status

Support level

Availability

onerror

EventListener

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

writable

Web Workers

6.0 or later

onmessage

EventListener

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

writable

Web Workers

6.0 or later

Back To Top

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.

Web Workers

6.0 or later

terminate()

Terminates the worker.

Web Workers

6.0 or later

Back To Top
Next topic: Touch API
Previous topic: StorageEvent methods

Was this information helpful? Send us your comments.