Queue publish calls while getting uuid from db

This commit is contained in:
Petros Angelatos 2014-05-12 00:36:09 +01:00 committed by Pablo Carranza Vélez
parent ca736233e7
commit 7c33f28724

View File

@ -21,7 +21,12 @@ Promise.promisifyAll(docker.getContainer().__proto__)
pubnub = PUBNUB.init(config.pubnub)
publish = null
# Queue up any calls to publish while we wait for the uuid to return from
# the sqlite db
publishQueue = []
publish = ->
publishQueue.push(arguments)
knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
uuid = uuid.value
@ -30,6 +35,9 @@ knex('config').select('value').where(key: 'uuid').then ([uuid]) ->
publish = (message) ->
pubnub.publish({channel, message})
# Replay queue now that we have initialised the publish function
publish.apply(null, args) for args in publishQueue
exports.kill = kill = (app) ->
docker.listContainersAsync(all: 1)
.then (containers) ->