<div dir="ltr">On Wed, Aug 20, 2008 at 5:36 PM, Ian Hickson <span dir="ltr"><ian@hixie.ch></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
I've received feedback from a number of people requesting a rethink to the<br>
API for creating and communicating with workers.<br>
<br>
Here is a skeleton of a new proposal. It makes the following changes:<br>
<br>
* Shared workers and dedicated workers get their own interfaces,<br>
inheriting from a common base interface, both for the global scope<br>
objects and for the objects returned when they are created.<br>
<br>
* Shared workers get a port per connection. Dedicated workers don't get a<br>
port, but they have a convenience method on the worker and on the<br>
worker's global object that allows for easy creation of ports to send<br>
threaded messages (direct replies).<br>
<br>
* Uses constructors instead of factory methods to create workers.<br>
<br>
* Removes 'onload' from the Worker objects.<br>
<br>
* Renamed "onunload" to "onclose" throughout.<br>
<br>
* Removes the "closing" boolean.<br>
<br>
* Adds a way to kill a dedicated worker.<br>
<br>
<br>
OUTSIDE<br>
<br>
// (abstract, never instantiated)<br>
[NoInterfaceObject] interface Worker {<br>
attribute EventListener onerror; // invoked if the worker fails to start<br>
attribute EventListener onclose; // invoked if the worker closes<br>
};<br>
<br>
interface DedicatedWorker : Worker {<br>
void close(); // kills the worker immediately, without cleanup</blockquote><div><br>Is the shutdown sequence initiated by this method call different then the shutdown sequence initiated by a call to self.close() from within the worker itself? The comment hints that it is... if so why?<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
// these all work the same as on MessagePorts:<br>
attribute EventListener onmessage; // receives messages from the worker<br>
boolean postMessage(in DOMString message);<br>
boolean postMessage(in DOMString message, in MessagePort, port);<br>
MessagePort startConversation(in DOMString message);<br>
};<br>
<br>
interface SharedWorker : Worker {<br>
readonly attribute MessagePort port; // local end of channel to worker<br>
};<br>
<br>
<br>
INSIDE<br>
<br>
// (abstract, never instantiated)<br>
[NoInterfaceObject] interface WorkerGlobalScope {<br>
void close();<br>
attribute EventListener onclose;<br>
<br>
readonly attribute WorkerGlobalScope self;<br>
readonly attribute WorkerLocation location;<br>
// also implements everything on WorkerUtils<br>
};<br>
<br>
[NoInterfaceObject] interface DedicatedWorkerGlobalScope : WorkerGlobalScope {<br>
// these all work the same as on MessagePorts:<br>
attribute EventListener onmessage; // receives messages from the owner<br>
boolean postMessage(in DOMString message);<br>
boolean postMessage(in DOMString message, in MessagePort, port);<br>
MessagePort startConversation(in DOMString message);<br>
};<br>
<br>
[NoInterfaceObject] interface DedicatedWorkerGlobalScope : WorkerGlobalScope {<br>
attribute EventListener onconnect; // called by createSharedWorker()<br>
readonly attribute DOMString name;<br>
};<br>
<br>
<br>
CREATING WORKERS<br>
<br>
To created workes, use constructors:<br>
<br>
var worker = new DedicatedWorker(url);<br>
var service = new SharedWorker(name, url);<br>
</blockquote><div><br>
Is it possible for a worker (shared or dedicated) to reload itself?<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<br>
Comments? <br></blockquote><div><br>How do workers and appCaches interact?<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><font color="#888888"><br>
--<br>
Ian Hickson U+1047E )\._.,--....,'``. fL<br>
<a href="http://ln.hixie.ch/" target="_blank">http://ln.hixie.ch/</a> U+263A /, _.. \ _\ ;`._ ,.<br>
Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'<br>
</font></blockquote></div><br></div>