Enclose publish queuing vars in their own closure

This commit is contained in:
Petros Angelatos 2014-05-13 03:29:33 +01:00 committed by Pablo Carranza Vélez
parent 7c33f28724
commit 39261f5d6b

View File

@ -23,11 +23,9 @@ pubnub = PUBNUB.init(config.pubnub)
# Queue up any calls to publish while we wait for the uuid to return from
# the sqlite db
publish = do ->
publishQueue = []
publish = ->
publishQueue.push(arguments)
knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
uuid = uuid.value
channel = "device-#{uuid}-logs"
@ -36,7 +34,9 @@ knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
pubnub.publish({channel, message})
# Replay queue now that we have initialised the publish function
publish.apply(null, args) for args in publishQueue
publish(args...) for args in publishQueue
return -> publishQueue.push(arguments)
exports.kill = kill = (app) ->
docker.listContainersAsync(all: 1)