Changes

Jump to: navigation, search

DOMWorkerThreads

1,380 bytes added, 16:33, 15 August 2008
no edit summary
};
interface Worker{
void postMessage(in DOMString aMessage);
};
[NoInterfaceObject] interface WorkerParent
{
void postMessage(in DOMString aMessage);
 
// event handler attributes
attribute EventListener onmessage;
};
[NoInterfaceObject] interface WorkerGlobalScope
readonly attribute WorkerGlobalScope self;
readonly attribute WorkerLocation location;
readonly attribute WorkerParent parent;
readonly attribute boolean closing;
void close();
=== Sample usage ===
 
This is a '''very''' suboptimal way of calculating a number in the Fibonacci sequence.
Main page:
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 1 ===
 
<blockquote>
<code>
<pre>
 
[NoInterfaceObject] interface WorkerFactory {
...
Worker createSharedWorker(in DOMString name, in DOMString scriptURL);
};
 
[NoInterfaceObject] interface WorkerParent {
void postMessage(in DOMString aMessage);
attribute EventListener onmessage;
};
 
</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 a shared <code>Worker</code> receives a message it can send data back to the sender using the <code>Event.source</code> property which is a <code>WorkerParent</code>.
 
Using <code>WorkerGlobalScope.postMessage</code> and <code>WorkerGlobalScope.onmessage</code> results in a message being sent to the first context that opened the shared worker (or nothing if that context is dead).
 
Downsides with this proposal:
* There is no way to communicate back unless first communicated to.
=== Proposal 2 ===
[NoInterfaceObject] interface WorkerFactory {
...
Worker createSharedWorkerMessagePort connectToSharedWorker(in DOMString name, in DOMString scriptURL);}; [NoInterfaceObject] interface WorkerGlobalScope { ... attribute EventListener onconnect;
};
</blockquote>
<code>createSharedWorkerconnectToSharedWorker</code> creates a new <code>Worker</code> object that if none exists for the given namethat interacts with the same <code>WorkerGlobalScope</code> as any previously existing <code>Worker</code>s.  When a shared <code>Worker</code> receives a message it can send data back to the sender using the <code>postMessageEvent.source</code> property which is called from within a shared <code>WorkerGlobalScopeWorkerParent</code> all connected . Using <code>WorkerWorkerGlobalScope.postMessage</code> objects will received that message through their and <code>WorkerGlobalScope.onmessage</code> propertyresults in a message being sent to the first context that opened the shared worker (or nothing if that context is dead).
Downsides with this proposal:* There is no way to communicate back unless first communicated to.* Thespecial treatment of the first context to open a shared worker.
Confirm
716
edits

Navigation menu