Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A pre-emption mechanism would be able receive the message and respond. At the very least a response of "I'm busy" is better than no response that could be for any number of reasons.

Shared data structures would enable this, and while you may not think they are very nice, I would prefer a not very nice solution to no solution whatsoever. I have seen discussions on various mailing that indicate that shared data structures will be implemented in some manner.

Look at the example number crunching worker given in the spec. https://html.spec.whatwg.org/multipage/workers.html#a-backgr...

    var n = 1;
    search: while (true) {
      n += 1;
      for (var i = 2; i <= Math.sqrt(n); i += 1)
        if (n % i == 0)
         continue search;
      // found a prime!
      postMessage(n);
    }
How would you implement this worker in such a way that the host page could call

  worker.postMessage( {"command": "startfrom", "value" : 131071} ); 
to get the prime calculator change it's search point?


Convert the while/for loops and recursion to continuation-passing style and bounce via nextTick/setTimeout to convince yourself that shared data structures still aren't required to fix this: only pre-emption.


I'm not sure I follow the bit about convincing myself. Going back to square one again with a setTimout/event loop renders much of the use of workers pointless, you are stuck back at the same restrictions as main thread JavaScript.

I agree pre-emption would allow this without shared data structures. It just seems that the solution we will be given in the end will be a shared model.

http://lars-t-hansen.github.io/ecmascript_sharedmem/shmem.ht...


You can get a lot of mileage out of specialised solutions, and I suspect we'll continue to see those instead of a shared model; in an answer to your question about finding prime numbers, simply kill the worker and start another one with a new initial state.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: