diff options
author | Holden Rohrer <hr@hrhr.dev> | 2020-01-20 16:14:54 -0500 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2020-01-20 16:14:54 -0500 |
commit | f2ed001161935fa7df2cb7b4af66f77a000ccf49 (patch) | |
tree | fd1d556f4978781f777e0255d80ffaadd22ef0f2 /tools | |
parent | 046e7035bccc632269c10d869837ead3b8695305 (diff) |
scheduler has .pause function
Diffstat (limited to 'tools')
-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){ |