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
- Ripple Emulator

View Supported Platform Table

APIOS 5.0OS 6.0OS 7.0PlayBookRipple
Worker Y Y Y YY
onmessage Y Y Y YY
postMessage Y Y Y YY
applicationCache   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 Only)
This API does not require a <permission> element to be declared in the configuration document of your BlackBerry WebWorks Application.

API Summary


Constructors



Properties

Worker


Worker (fileName : String)

Supported Platform(s)

 - BlackBerry OS 5.0+
 - BlackBerry PlayBook
 - Ripple Emulator

Description

Creates a new Worker object.



Parameter Type Description
fileName String The name of the javascript file to be executed by the worker.

onmessage


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

Supported Platform(s)

 - BlackBerry OS 5.0+
 - BlackBerry PlayBook
 - Ripple Emulator

Description

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



Parameter Type Description
messageText String
Optional
text message.
senderId String
Optional
sender ID.
messageObject Object
Optional
message object when send.

postMessage


void postMessage(message : Object)

Supported Platform(s)

 - BlackBerry OS 5.0+
 - BlackBerry PlayBook
 - Ripple Emulator

Description

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.



Parameter Type Description
message Object A message to post when worker is created.

Code Example(s)

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:


Property Type Description Supported Platform(s)
applicationCache ApplicationCache The ApplicationCache object associated with this worker
 - BlackBerry OS 6.0+
 - BlackBerry PlayBook
 - Ripple Emulator

Documentation generated by JsDoc Toolkit 2.4.0 on Sun Dec 30 2012 13:31:21 GMT-0500 (EST)