aboutsummaryrefslogtreecommitdiff
path: root/examples
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 /examples
parent2ca99ea944868a7c0a90ebfa9b6eb8669ca81732 (diff)
added queue.js to simplify jarvis
Diffstat (limited to 'examples')
-rw-r--r--examples/jarvis.js16
1 files changed, 3 insertions, 13 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js
index d60bc44..00b4610 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -5,6 +5,7 @@ const Socket = require('../socket');
const getdims = require('../utils/getdims');
const tilekeys = require('../utils/tilekeys');
const Search = require('../tools/search');
+const Queue = require('../tools/queue');
var main = new Socket();
@@ -57,21 +58,10 @@ function identity(sender){
let response = new Space();
response.adhoc('yes, my liege');
-let queue = []; // Must be expanded to handle actual use cases
-let open = true;
-function dequeue(){
- if (queue.length == 0)
- open = true;
- else{
- open = false;
- main.write(queue.shift()) // Make more general (possibly a function pointer or a conf variable)
- setTimeout(dequeue, 1000);
- }
-}
+let writes = new Queue(1000, 200, (elems) => main.write(elems));
function respond(coord){
console.log('called at', coord);
response.loc = coord;
- queue.push(response.towrite());
- if (open) dequeue();
+ writes.enqueue(...response.towrite());
}