diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/jarvis.js | 16 |
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()); } |