Re: Web workers: synchronously handling events

On Tue, Dec 28, 2010 at 3:06 PM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
> Yes, by pausing every once in a while with setTimeout and letting the
> event loop spin.
>
> Doing anything else would break javascript's appearance of single-threadedness.

I'm not suggesting that events should run on their own in the middle
of script execution.  I'm suggesting that code should be able to
explicitly, synchronously run the event loop, only for messages from a
specific message port.  I don't think this makes Javascript less
single-threaded-looking; it's analogous to doing a nonblocking read()
from a TTY in Unix, to retrieve the user's next keystroke.

> I agree that it's not particularly nice to write your algorithms like
> this, but it's already familiar to any js dev who uses any algorithm
> with significant running time.  If we were to fix this, it needs to be
> done at the language level, because there are language-level issues to
> be solved that can't be hacked around by a specialized solution.

That's a workaround for doing long-running computations in a UI
thread.  The very reason for using worker threads to do computation in
the first place is so this sort of hack isn't necessary.

-- 
Glenn Maynard

Received on Tuesday, 28 December 2010 20:30:05 UTC