[whatwg] Combining the DedicatedWorker and SharedWorker interfaces

Alexey Proskuryakov ap at webkit.org
Wed Nov 5 06:56:42 PST 2008


Nov 5, 2008, в 1:11 AM, Jonas Sicking написал(а):

> main.js:
> w = new Worker('worker.js');
> p = w.connect();
> p.postMessage(17);
> p.onmessage = function(e) {
>  answer = e.data;
> }


I prefer to think of it as:

window.onload = function() {
     var worker = new Worker('encrypt.js');
     var workerPort = worker.connect();
     workerPort.onmessage = processWorkerReply;
}

function spawnEncryptData(id, data) {
    workerPort.postMessage("encrypt " + id + " " + data);
}

Aside from one time setup (which usually needs to be performed in  
advance), the "simple case" looks no different, but there is no  
confusion about which port to use.

- WBR, Alexey Proskuryakov




More information about the whatwg mailing list