[whatwg] WebWorkers vs. Threads

Sorry, I do not get it.  Where does the value of (la) make it into
(e.message)?

-----Original Message-----
From: whatwg-bounces@lists.whatwg.org
[mailto:whatwg-bounces at lists.whatwg.org] On Behalf Of Aaron Boodman
Sent: Wednesday, August 13, 2008 10:04 PM
To: Shannon
Cc: WHAT working group; Kristof Zelechovski; Jonas Sicking
Subject: Re: [whatwg] WebWorkers vs. Threads


You're right that if you try to use workers like threads, you end up
with threads. A more message-passing style implementation is easier.
In particular you would not want to allow the worker to 'get' and
'set' individual variables, but pass it messages about work you would
like it to perform, and have it pass back messages about the result.
This is less flexible than threading but easier to reason about.

// main.js
var la = 0; // what is with this variable name?
var worker = createWorker("worker.js");
worker.port.addEventListener("message", function(e) {
  la = parseInt(e.message);
  alert(la);
}, false);

// worker.js
workerGlobalScope.port.addEventListener("message", function(e) {
  workerGlobalScope.port.sendMessage(
someLongRunningFunction(parseInt(e.message)));
}, false);

Received on Thursday, 14 August 2008 00:23:46 UTC