diff options
| -rw-r--r-- | tools/schedule.js | 10 | 
1 files changed, 10 insertions, 0 deletions
| diff --git a/tools/schedule.js b/tools/schedule.js index e2af9db..42ec127 100644 --- a/tools/schedule.js +++ b/tools/schedule.js @@ -24,6 +24,7 @@ exports.Queue = function(delayms, maxExport, call){    let prios = []; // Array of priorities (keys of jobs), sorted.    let open = true; // Is dequeue() allowed to be called (i.e., has the timeout expired?)    let disab = true; // Is the queue disabled? +  let pauseCall = null; // Either null or a function which will replace the next dequeue() call.    this.enqueue = function(job){      if (! job[0]) return; @@ -46,6 +47,10 @@ exports.Queue = function(delayms, maxExport, call){    this.disable = function(){      disab = true;    } + +  this.pause = function(call){ // run `call()` instead of `dequeue()` when timeout expires. Just do it once (overwrites other calls) +    pauseCall = call; +  }    function dequeue(){      // Wraps getNumOrAll, managing open/disab, and concatenating possibly multiple layers @@ -57,6 +62,11 @@ exports.Queue = function(delayms, maxExport, call){        open = true;        return;      } +    if (pauseCall){ +      call(); +      pauseCall = null; +      return; +    }      open = false;      let data = [];      while (prios.length > 0 && data.length < maxExport){ | 
