diff --git a/lib/assets/javascripts/flowerbox.js.coffee b/lib/assets/javascripts/flowerbox.js.coffee index eb0414e..d28434d 100644 --- a/lib/assets/javascripts/flowerbox.js.coffee +++ b/lib/assets/javascripts/flowerbox.js.coffee @@ -4,6 +4,7 @@ Flowerbox = Flowerbox.contact('ping') messageQueue: [] + pulling: false contact: (url, data...) -> Flowerbox.started = true @@ -12,16 +13,19 @@ Flowerbox = message = [ url, data ] Flowerbox.messageQueue.push(message) - Flowerbox.queuePuller() if Flowerbox.socket + if Flowerbox.socket && !Flowerbox.pulling + Flowerbox.queuePuller() started: false done: false queuePuller: -> + Flowerbox.pulling = true + if Flowerbox.messageQueue.length > 0 message = Flowerbox.messageQueue.shift() - Flowerbox.socket.send JSON.stringify(message), {}, -> + Flowerbox.socket.onmessage = (data) -> if message[0] == 'results' if __$instrument? Flowerbox.socket.send JSON.stringify(['instrument', __$instrument]) {}, -> @@ -31,6 +35,10 @@ Flowerbox = Flowerbox.queuePuller() + Flowerbox.socket.send JSON.stringify(message) + else + setTimeout(Flowerbox.queuePuller, 10) if !Flowerbox.done + fail: -> class Flowerbox.Exception diff --git a/lib/flowerbox/server.rb b/lib/flowerbox/server.rb index f5bf070..761bd99 100644 --- a/lib/flowerbox/server.rb +++ b/lib/flowerbox/server.rb @@ -49,7 +49,11 @@ module Flowerbox output = runner.send(command, [ data ].flatten) - ws.send(output) if command == 'load' + if command == 'load' + ws.send(output) + else + ws.send("ok") + end } end