W3C home > Mailing lists > Public > public-webapps@w3.org > July to September 2014

Blocking message passing for Workers

From: Alan deLespinasse <adelespinasse@gmail.com>
Date: Fri, 8 Aug 2014 13:49:25 -0400
Message-ID: <CAMuhF-+RLH_fAn9beRVHMQQYBu2Or0mi6M6de=45bTt3AKgnLg@mail.gmail.com>
To: public-webapps@w3.org
I would find it extremely useful to have a function available to a Worker
that would block and wait for a message from another Worker or from the
main thread. For example, instead of:

onmessage = function(event) {
  // Do some work
  // Save all state for next time

I'd like to have something like this:

while (true) {
  var data = waitForMessage().data;
  // Do some work


var subworker = new Worker('subworker.js');
while (true) {
  var data = subworker.waitForMessage().data;
  // Do some work

A timeout would probably be nice to have. I don't have an opinion on
whether having a timeout should be optional or required.

Of course you wouldn't want to do this in the main thread, just as you
wouldn't use a synchronous XMLHttpRequest. But it's fine to have a Worker
loop indefinitely and block while waiting for results from somewhere else.

Is this a possibility?

Is there already some way to do this that I'm not aware of?

Do I need to expand on my reasons for wanting such a thing?
Received on Friday, 8 August 2014 17:49:52 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:14:26 UTC