Skip to content

Commit

Permalink
fixes moscajs#12
Browse files Browse the repository at this point in the history
  • Loading branch information
behrad committed Nov 20, 2018
1 parent c828e2e commit 885efcb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ function CachedPersistence (opts) {
that._trie.remove(sub.topic, sub)
}
}
var action = packet.topic === newSubTopic ? 'sub' : 'unsub'
var waiting = that._waiting[clientId + '-' + action]
delete that._waiting[clientId + '-' + action]
var action = packet.topic === newSubTopic ? 'sub_' : 'unsub_'
var key = clientId + '-' + action
if (decoded.subs.length > 0) {
key = clientId + '-' + action + decoded.subs[0].topic
}
var waiting = that._waiting[key]
that._waiting[key] = undefined
if (waiting) {
process.nextTick(waiting)
}
Expand All @@ -75,7 +79,7 @@ CachedPersistence.prototype._addedSubscriptions = function (client, subs, cb) {

var errored = false

this._waitFor(client, 'sub', function (err) {
this._waitFor(client, 'sub_' + subs[0].topic, function (err) {
if (!errored && err) {
return cb(err)
}
Expand Down Expand Up @@ -120,8 +124,12 @@ CachedPersistence.prototype._removedSubscriptions = function (client, subs, cb)
return
}
var errored = false
var key = subs

this._waitFor(client, 'unsub', function (err) {
if (subs.length > 0) {
key = subs[0].topic
}
this._waitFor(client, 'unsub_' + key, function (err) {
if (!errored && err) {
return cb(err)
}
Expand Down

0 comments on commit 885efcb

Please sign in to comment.