Skip to content

Commit

Permalink
Merge pull request #97 from omsmith/fix-multi-client-native-promises
Browse files Browse the repository at this point in the history
Fix multi client native promises
  • Loading branch information
omsmith authored Dec 19, 2017
2 parents b388610 + 220943a commit ad5faaf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Host.prototype.connect = function connect() {
var me = this;
return new Promise(function(resolve/*, reject*/) {
me.onEvent('ready', function() {
if (me._isConnected) {
return;
}

resolve(Port.prototype.connect.call(me));
});
me.open();
Expand Down
3 changes: 3 additions & 0 deletions test/__throw_rejected_promises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

process.on('unhandledRejection', e => { process._rawDebug(e); process.exit(1); });
10 changes: 9 additions & 1 deletion test/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,16 @@ describe('host', () => {
onEvent.should.have.been.calledWith('ready');
});

it('should not error when client connects after initial client', (done) => {
host
.connect()
.then(() => {
host._receiveEvent('ready');
})
.then(done, done);
host._receiveEvent('ready');
});
});

});

});

0 comments on commit ad5faaf

Please sign in to comment.