From f2ed001161935fa7df2cb7b4af66f77a000ccf49 Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Mon, 20 Jan 2020 16:14:54 -0500
Subject: scheduler has .pause function
---
tools/schedule.js | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'tools')
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){
--
cgit