- From: Ian Hickson <ian@hixie.ch>
 - Date: Thu, 21 Aug 2008 00:36:28 +0000 (UTC)
 
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?
-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Wednesday, 20 August 2008 17:36:28 UTC