handle pending channel creation

master
Juanfran 2016-05-04 09:26:37 +02:00
parent aaa89996a2
commit 7568352305
2 changed files with 10 additions and 2 deletions

View File

@ -23,7 +23,7 @@
"gulp-plumber": "^1.0.1"
},
"dependencies": {
"amqplib": "^0.4.0",
"amqplib": "^0.4.1",
"base64-url": "^1.2.1",
"bluebird": "^2.9.10",
"node-uuid": "^1.4.2",

View File

@ -39,6 +39,7 @@ getConnection = do ->
# Return the user channel
channels = do ->
chs = {}
pendingChannels = {}
removeClient = (client_id) ->
get(client_id).then (channel) ->
@ -47,7 +48,12 @@ channels = do ->
delete chs[client_id]
get = (client_id) ->
return new Promise (resolve, reject) ->
if pendingChannels[client_id]
return pendingChannels[client_id]
pendingChannels[client_id] = new Promise (resolve, reject) ->
delete pendingChannels[client_id]
if !chs[client_id]
getConnection()
.then (connection) -> connection.createChannel()
@ -57,6 +63,8 @@ channels = do ->
else
resolve(chs[client_id])
return pendingChannels[client_id]
return {
removeClient: removeClient
get: get