aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-07-16 17:13:47 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-07-16 17:13:47 -0400
commit327ed17b1d66f89a2165d626775698edbc2c0e9d (patch)
treede1b1a18517f112112b61dc5b7dfdb1e5d256607 /tools
parent246a4582eda90825a6beaaa963c8d3772c6cf8dc (diff)
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.
Diffstat (limited to 'tools')
-rw-r--r--tools/queue.js7
1 files changed, 5 insertions, 2 deletions
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);
}
}