[whatwg] Combining the DedicatedWorker and SharedWorker interfaces

Alexey Proskuryakov ap at webkit.org
Tue Nov 4 05:42:34 PST 2008


Nov 4, 2008, в 10:08 AM, Aaron Boodman написал(а):

> This lack of generality bothers me on an aesthetic level, but I also
> think it has the following real problems:

Agreed on all points.

> * Add startConversation() to SharedWorker, but rename it "connect()"

Makes sense - when we had other MessagePort methods mirrored to worker  
global scope, this name was natural, but it no longer is now.

> Here's an example in code:
>
> // dedicated workers (outside)
> var worker = new Worker("foo.js");
> var port = worker.connect();
> port.onmessage = function() { }
> port.postMessage("ping");
>
> // dedicated workers (inside)
> onconnect = function(e) {
>  e.port.onmessage = function(e) {
>    e.port.postMessage("pong");
>  }
> }

I think this can be written as (note the different name of  
MessageEvent attribute, and the use of "this" in onmessage):
onconnect = function(e) {
  e.messagePort.onmessage = function() {
    this.postMessage("pong");
  }
}

In general, one extra line of code doesn't look like a huge downside -  
this is not something that needs to be done again and again in client  
code.

> Shared workers are exactly the same except the constructor is
> SharedWorker("foo.js", "foo");


Is there any benefit in having a different name for this constructor?  
If dedicated and shared workers are going to have identical  
implementation (notably, if they have exactly the same lifetime), I  
don't see any benefit in making them look different.

- WBR, Alexey Proskuryakov





More information about the whatwg mailing list