Webmaster SetTimeout

What if I want the web worker to pause if I cannot continue processing the data and try a second later? Can I do it this way inside a web worker?

var doStuff = function() {
    if( databaseBusy() ) {
        setTimeout(doStuff, 1000);
    } else {
        doStuffIndeed();
    }
}

I get an Uncaught RangeError: the maximum size of the call stack exceeds , and something tells me about it due to the above code.

+3
source share
1 answer

"" , " worker.postMessage() ", , setTimeout() . setTimeout() , . - - onmessage , .

setTimeout, . :

worker.js

var workQueue = [];
addEventListener('message',function(evt){
  workQueue.push(evt.data);
  doStuff();
},false);

function doStuff(){
  while (!databaseBusy()) doStuffIndeed(workQueue.shift());
  if (workQueue.length) setTimeout(doStuff,1000);
}
  • , , tryToProcess.
  • tryToProcess , .
  • , , 1 .
+2

All Articles