From 327ed17b1d66f89a2165d626775698edbc2c0e9d Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Thu, 16 Jul 2020 17:13:47 -0400 Subject: added nword protector using an add'l id func to Queue This should be added to sched.Queue so (even if it requires a somewhat convoluted workflow), any write may be tracked. --- tools/queue.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tools/queue.js') diff --git a/tools/queue.js b/tools/queue.js index d8853e4..f45ec80 100644 --- a/tools/queue.js +++ b/tools/queue.js @@ -3,15 +3,18 @@ module.exports = function(delayms, maxExport, call){ let queue = []; - let open = true; // The meaning of this variable is complicated, so watch closely + let id = 0; + let open = true; // Has call() run in the past delayms ms? let getObjs = (maxExport == 1) ? // Should call be given one object or an array? () => queue.shift() : () => queue.splice(0, maxExport); this.enqueue = function(arr){ + id += arr.length; for (item of arr) queue.push(item); if (open) dequeue(); + return id; } disabled = true; // Used to disable pushes when non-sensical like if a socket is down @@ -31,7 +34,7 @@ module.exports = function(delayms, maxExport, call){ open = true; else { open = false; - call(getObjs()); + call(getObjs(), id-queue.length); setTimeout(dequeue, delayms); } } -- cgit