[whatwg] Combining the DedicatedWorker and SharedWorker interfaces

Aaron Boodman aa at google.com
Tue Nov 4 09:02:01 PST 2008


2008/11/4 Alexey Proskuryakov <ap at webkit.org>:
> Nov 4, 2008, в 10:08 AM, Aaron Boodman написал(а):
>> 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");
>  }
> }

Right you are. Thanks for fixing.

>> 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.

I don't have a strong opinion on this either way.

- a



More information about the whatwg mailing list