aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorHolden Rohrer <holden.rohrer@gmail.com>2019-12-24 20:55:52 -0500
committerHolden Rohrer <holden.rohrer@gmail.com>2019-12-27 14:52:44 -0500
commit4bd0a90631cc07d1433a11079bfc2d54d51fb644 (patch)
tree976b19921de5af07170716104785948cdbf2978d /tools
parent2ca99ea944868a7c0a90ebfa9b6eb8669ca81732 (diff)
added queue.js to simplify jarvis
Diffstat (limited to 'tools')
-rw-r--r--tools/queue.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/queue.js b/tools/queue.js
new file mode 100644
index 0000000..ebe17cd
--- /dev/null
+++ b/tools/queue.js
@@ -0,0 +1,24 @@
+// A generalized queue object for rapid responses (doesn't do prioritization or algorithmic timesharing)
+
+module.exports = function(delayms, maxExport, call){
+ let queue = [];
+ let open = true;
+ let getObjs = (maxExport == 1) ?
+ () => queue.shift() :
+ () => queue.splice(0, maxExport) ;
+ this.enqueue = function(){
+ for (let i = 0; i < arguments.length; i++)
+ queue.push(arguments[i]);
+ if (open) dequeue();
+ }
+
+ function dequeue(){
+ if (queue.length == 0)
+ open = true;
+ else {
+ open = false;
+ call(getObjs());
+ setTimeout(dequeue, delayms);
+ }
+ }
+}