- From: Alan deLespinasse <adelespinasse@gmail.com>
- Date: Fri, 8 Aug 2014 13:49:25 -0400
- To: public-webapps@w3.org
- Message-ID: <CAMuhF-+RLH_fAn9beRVHMQQYBu2Or0mi6M6de=45bTt3AKgnLg@mail.gmail.com>
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
}
or:
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