[whatwg] Workers proposal

This is looking great. A few comments though (of course :) )

Do we really need the SharedWorker interface. I.e. couldn't we just 
return a MessagePort? This would probably require that we use a factory 
function rather than a constructor, like "getPortForSharedWorker" or 
some such. In other words, do we really need onclose and onerror for 
shared workers (onerror seems to make some sense, onclose i'm less sure 
about).

I think startConversation makes as much sense on shared workers as 
dedicated ones, so moving that API up to Worker/WorkerGlobalScope seems 
like a good idea.

If we keep the constructors (see first paragraph), I would prefer the 
syntax "new Worker" over "new DedicatedWorker".

/ Jonas

Ian Hickson wrote:
> I've received feedback from a number of people requesting a rethink to the 
> API for creating and communicating with workers.
> 
> Here is a skeleton of a new proposal. It makes the following changes:
> 
>  * Shared workers and dedicated workers get their own interfaces, 
>    inheriting from a common base interface, both for the global scope 
>    objects and for the objects returned when they are created.
> 
>  * Shared workers get a port per connection. Dedicated workers don't get a 
>    port, but they have a convenience method on the worker and on the 
>    worker's global object that allows for easy creation of ports to send 
>    threaded messages (direct replies).
> 
>  * Uses constructors instead of factory methods to create workers.
> 
>  * Removes 'onload' from the Worker objects.
> 
>  * Renamed "onunload" to "onclose" throughout.
> 
>  * Removes the "closing" boolean.
> 
>  * Adds a way to kill a dedicated worker.
> 
> 
> OUTSIDE
> 
> // (abstract, never instantiated)
> [NoInterfaceObject] interface Worker {
>   attribute EventListener onerror; // invoked if the worker fails to start
>   attribute EventListener onclose; // invoked if the worker closes
> };
> 
> interface DedicatedWorker : Worker {
>   void close(); // kills the worker immediately, without cleanup
> 
>   // these all work the same as on MessagePorts:
>   attribute EventListener onmessage; // receives messages from the worker
>   boolean postMessage(in DOMString message);
>   boolean postMessage(in DOMString message, in MessagePort, port);
>   MessagePort startConversation(in DOMString message);
> };
> 
> interface SharedWorker : Worker {
>   readonly attribute MessagePort port; // local end of channel to worker
> };
> 
> 
> INSIDE
> 
> // (abstract, never instantiated)
> [NoInterfaceObject] interface WorkerGlobalScope {
>   void close();
>   attribute EventListener onclose;
> 
>   readonly attribute WorkerGlobalScope self;
>   readonly attribute WorkerLocation location;
>   // also implements everything on WorkerUtils
> };
> 
> [NoInterfaceObject] interface DedicatedWorkerGlobalScope : WorkerGlobalScope {
>   // these all work the same as on MessagePorts:
>   attribute EventListener onmessage; // receives messages from the owner
>   boolean postMessage(in DOMString message);
>   boolean postMessage(in DOMString message, in MessagePort, port);
>   MessagePort startConversation(in DOMString message);
> };
> 
> [NoInterfaceObject] interface DedicatedWorkerGlobalScope : WorkerGlobalScope {
>   attribute EventListener onconnect; // called by createSharedWorker()
>   readonly attribute DOMString name;
> };
> 
> 
> CREATING WORKERS
> 
> To created workes, use constructors:
> 
>    var worker = new DedicatedWorker(url);
>    var service = new SharedWorker(name, url);
> 
> 
> Comments?
> 

Received on Wednesday, 20 August 2008 22:32:18 UTC