Changes

Jump to: navigation, search

DOMWorkerThreads

1,402 bytes removed, 22:52, 13 August 2008
no edit summary
== Web Worker API Proposal ==
 
== Abstract ==
 
This is an API '''proposal''' for DOM Worker Threads.
 
At this time this document is not complete. While we invite discussion on this topic, this is not a stable API proposal, and Mozilla won't implement anything based on it till it becomes stable.
 
Look for a post to mozilla.dev.platform when this proposal is ready to be discussed.
 
== Introduction ==
 
=== Use Cases ===
 
=== Terminology ===
 
A '''worker''' is an execution context for JavaScript that runs off of the main UI thread. The global scope for a worker is almost empty - familiar objects such as <code>window</code> and <code>document</code> are not available, nor is the Mozilla-specific <code>Components</code> object.
 
A '''worker pool''' is a collection of related workers. Workers within a pool can communicate with each other freely, but workers cannot communicate with workers from another pool.
 
== Conformance ==
 
== Dependencies ==
== API Proposal ==
readonly attribute boolean closing;
void close();
 
void postMessage(in DOMString aMessage);
// event handler attributes
attribute EventListener onmessage;
attribute EventListener onunload;
</code>
</blockquote>
 
=== The worker's scope ===
 
The worker's scope is far more limited. See <code>WorkerGlobalScope</code> above for details.
=== Sample usage ===
Main page:
<blockquote>
<code>
<pre>
<!DOCTYPE HTML PUBLIC worker = createWorker("-//W3C//DTD HTML 4f.0 Transitional//ENjs">);<html> <title>Test threads</title> <body> <script language="javascript"> var scriptToRun worker.onmessage = 'function messageListener(message, sourcee) { ' + ' dump alert("Worker: The 100th Fibonacci number is " + message + "\\n"e.data); ' + '} ' + 'for worker.postMessage(var i = 0100); i < 10000000; i++) { ' +/pre> ' </* do something *code></ ' + '} '+ 'postMessageToPool("Done!"); ';blockquote>
var wp = navigatorf.newWorkerPool();js:<blockquote><code><pre> wp.messageListener onmessage = function(message, sourcee) { dump if ("Pool: " + message + "\n"); }; wpe.errorListener data <= function(error, source1) { dump postMessage("Pool: error = '" + error + "'\n"e.data); }
var threads w1 = []createWorker("f.js"); for (var i w1.onmessage = 0; i < 10handler; i++) { var thread = wp w1.createWorkerpostMessage(scriptToRune.data - 1); thread.postMessage w2 = createWorker("hellof.js"); threads w2.pushonmessage = handler; w2.postMessage(threade.data - 2); }
</script>c = 0; </body></html>sum = 0;
function handler(e) {
sum += parseInt(e.data);
if (++c == 2) {
postMessage(sum);
}
}
</pre>
</code>
</blockquote>
 
== Not In This Specification ==
== References ==
The only thing I've seen so far is the [http://code.google.com/apis/gears/api_workerpool.html Google Gears WorkerPool API]. We would certainly like to provide a compatibility API that would make migrating Gears code trivial. == Acknowledgements ==
Confirm
716
edits

Navigation menu