aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/jarvis.js25
1 files changed, 11 insertions, 14 deletions
diff --git a/examples/jarvis.js b/examples/jarvis.js
index f5a3ce2..d60bc44 100644
--- a/examples/jarvis.js
+++ b/examples/jarvis.js
@@ -56,25 +56,22 @@ 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 send(){
- if (queue.length == 0) open = true;
+function dequeue(){
+ if (queue.length == 0)
+ open = true;
else{
- main.write(queue.shift());
- setTimeout(send, 1000);
+ open = false;
+ main.write(queue.shift()) // Make more general (possibly a function pointer or a conf variable)
+ setTimeout(dequeue, 1000);
}
}
+
function respond(coord){
- response.loc = coord;
console.log('called at', coord);
- if (open){
- main.write(response.towrite());
- open = false;
- setTimeout(send, 1000);
- } else {
- queue.push(response.towrite());
- }
- send(response.towrite());
- main.write(response.towrite());
+ response.loc = coord;
+ queue.push(response.towrite());
+ if (open) dequeue();
}