Skip to content

Commit

Permalink
Merge b975ab1 into 91cae28
Browse files Browse the repository at this point in the history
  • Loading branch information
alecgibson committed Mar 27, 2024
2 parents 91cae28 + b975ab1 commit 27a2b3c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/client/presence/presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ Presence.prototype.destroy = function(callback) {
[
function(next) {
async.each(localIds, function(presenceId, next) {
presence.localPresences[presenceId].destroy(next);
var localPresence = presence.localPresences[presenceId];
if (!localPresence) return next();
localPresence.destroy(next);
}, next);
},
function(next) {
Expand Down
26 changes: 26 additions & 0 deletions test/client/presence/presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,32 @@ describe('Presence', function() {
], errorHandler(done));
});

it('does not throw if LocalPresence destroys before Presence', function(done) {
var localPresence1 = presence1.create('presence-1');

async.series([
presence1.subscribe.bind(presence1),
function(next) {
// Middleware that ensures the presence update replies before the
// unsubscribe, so the local presence is destroyed first
var replies = [];
backend.use('reply', function(message, cb) {
if (!replies) return cb();
if (message.reply.a !== 'p') return replies.push(cb);
var _replies = replies;
replies = null;
cb();
_replies.forEach(function(reply) {
reply();
});
});

presence1.destroy(next);
localPresence1.destroy(errorHandler(done));
}
], done);
});

it('throws if trying to create local presence when wanting destroy', function(done) {
presence2.destroy(errorHandler(done));
expect(function() {
Expand Down

0 comments on commit 27a2b3c

Please sign in to comment.