HTML5 Web Workers

Web Workers objects act as if they had an implicit MessagePort associated with them. This port is part of a channel that is set up when the worker is created and never be garbage collected before the Web Workers object. Only DedicatedWorker is supported.


Learning Resources:

Sample - Using HTML5 Web Worker Sample that demonstrates how to use the HTML5 Web Workers API [BlackBerry Developer Resource Center].

Supported Platform(s)

- BlackBerry OS 5.0+
- BlackBerry PlayBook 1.0+
- BlackBerry 10
- Ripple Emulator
View Supported Platform Table
APIBB5.0BB6.0BB7.0PB1.0PB2.0BB10Ripple
Worker Y Y Y Y Y YY
onmessage Y Y Y Y Y YY
postMessage Y Y Y Y Y YY
applicationCache   Y Y Y Y YY

Configuration Document Settings

To use all of the API described for this object, you must ensure the following settings are in your configuration document:

This API does not require a <feature> element to be declared in the configuration document of your BlackBerry WebWorks Application.

Permission Elements (PlayBook and BlackBerry 10+)
This API does not require a <permission> element to be declared in the configuration document of your BlackBerry WebWorks Application.

Constructors


Functions


Constructors

Worker (fileName : String)

Creates a new Worker object.


Supported Platforms
 - BlackBerry OS 5.0+
 - BlackBerry PlayBook 1.0+
 - BlackBerry 10
 - Ripple Emulator


Parameters
fileName The name of the javascript file to be executed by the worker.

Functions

void onmessage ([messageText : String], [senderId : String], [messageObject : Object])


The onmessage is the event handler as IDL attributes to Web Workers ojbect.


Supported Platforms
 - BlackBerry OS 5.0+
 - BlackBerry PlayBook 1.0+
 - BlackBerry 10
 - Ripple Emulator


Parameters
messageText text message.
senderId sender ID.
messageObject message object when send.

void postMessage (message : Object)


The postMessage() method on Web Workers objects invoked the method of the same name on the port, with the same arguments, and returned the same return value.


Supported Platforms
 - BlackBerry OS 5.0+
 - BlackBerry PlayBook 1.0+
 - BlackBerry 10
 - Ripple Emulator


Parameters
message A message to post when worker is created.

Code Example:
Main script:

<script type="text/javascript">
  var worker = new Worker('doWork.js');

  worker.addEventListener('message', function(e) {
       console.log('Worker said: ', e.data);
   }, false);

</script>

doWork.js (the worker):

  self.addEventListener('message', function(e) {
       self.postMessage(e.data);
   }, false);

Properties

ApplicationCache applicationCache


The ApplicationCache object associated with this worker


Supported Platforms
 - BlackBerry OS 6.0+
 - BlackBerry PlayBook 1.0+
 - BlackBerry 10
 - Ripple Emulator

Documentation generated by JsDoc Toolkit 2.4.0 on Mon Feb 11 2013 14:51:33 GMT-0500 (EST)