Changes

Jump to: navigation, search

DOMWorkerThreads

910 bytes added, 01:14, 14 August 2008
no edit summary
<code>
<pre>
 
[NoInterfaceObject] interface WorkerFactory {
Worker createWorker(in DOMString scriptURL);
};
 
interface Worker
{
attribute EventListener onload;
attribute EventListener onunload;
};
 
[NoInterfaceObject] interface WorkerParent
{
void postMessage(in DOMString aMessage);
 
// event handler attributes
attribute EventListener onmessage;
};
readonly attribute WorkerGlobalScope self;
readonly attribute WorkerLocation location;
readonly attribute WorkerParent parent;
readonly attribute boolean closing;
void close();
 
void postMessage(in DOMString aMessage);
// event handler attributes
attribute EventListener onmessage;
attribute EventListener onunload;
void showNotification(in DOMString title, in DOMString subtitle, in DOMString description);
void showNotification(in DOMString title, in DOMString subtitle, in DOMString description, in VoidCallback onclick);
};
 
[NoInterfaceObject] interface WorkerFactory {
Worker createWorker(in DOMString scriptURL);
};
<code>
<pre>
parent.onmessage = function(e) {
if (e.data <= 1)
postMessage(e.data);
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 API that would make migrating Gears code trivial.
 
== API Proposal For Shared Workers ==
 
If we want to support shared workers in the initial release of this spec, here are two proposals that will work with the above initial API.
 
=== Proposal 2 ===
 
<blockquote>
<code>
<pre>
 
[NoInterfaceObject] interface WorkerFactory {
...
Worker createSharedWorker(in DOMString name, in DOMString scriptURL);
};
 
</pre>
</code>
</blockquote>
 
<code>createSharedWorker</code> creates a new <code>Worker</code> object that interacts with the same <code>WorkerGlobalScope</code> as any previously existing <code>Worker</code>s. When <code>postMessage</code> is called from within a shared <code>WorkerGlobalScope</code> all connected <code>Worker</code> objects will received that message through their <code>onmessage</code> property.
 
The
Confirm
716
edits

Navigation menu