From 39261f5d6bc254552260a55c7bfc533ed0d4aaf8 Mon Sep 17 00:00:00 2001 From: Petros Angelatos Date: Tue, 13 May 2014 03:29:33 +0100 Subject: [PATCH] Enclose publish queuing vars in their own closure --- src/application.coffee | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/application.coffee b/src/application.coffee index e50f2dfc..8fffeda4 100644 --- a/src/application.coffee +++ b/src/application.coffee @@ -23,20 +23,20 @@ pubnub = PUBNUB.init(config.pubnub) # Queue up any calls to publish while we wait for the uuid to return from # the sqlite db -publishQueue = [] +publish = do -> + publishQueue = [] -publish = -> - publishQueue.push(arguments) + knex('config').select('value').where(key: 'uuid').then ([uuid]) -> + uuid = uuid.value + channel = "device-#{uuid}-logs" -knex('config').select('value').where(key: 'uuid').then ([uuid]) -> - uuid = uuid.value - channel = "device-#{uuid}-logs" + publish = (message) -> + pubnub.publish({channel, message}) - publish = (message) -> - pubnub.publish({channel, message}) + # Replay queue now that we have initialised the publish function + publish(args...) for args in publishQueue - # Replay queue now that we have initialised the publish function - publish.apply(null, args) for args in publishQueue + return -> publishQueue.push(arguments) exports.kill = kill = (app) -> docker.listContainersAsync(all: 1)