Skip to content

Commit

Permalink
Wrap more immediate errors in 0 length timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Jan 6, 2020
1 parent d21d746 commit 9038a7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/web3-core-subscriptions/src/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ Subscription.prototype.subscribe = function() {
// TODO subscribe here? after the past logs?

} else {
_this.callback(err, null, _this);
_this.emit('error', err);
setTimeout(function(){
_this.callback(err, null, _this);
_this.emit('error', err);
},0);
}
});
}
Expand Down Expand Up @@ -289,8 +291,10 @@ Subscription.prototype.subscribe = function() {
}
});
} else {
_this.callback(err, false, _this);
_this.emit('error', err);
setTimeout(function(){
_this.callback(err, false, _this);
_this.emit('error', err);
},0);
}
});

Expand Down
10 changes: 10 additions & 0 deletions test/eth.subscribe.ganache.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ describe('subscription connect/reconnect', function() {
});
});

it('subscription emits a connected event', function(done){
subscription = web3.eth
.subscribe('newBlockHeaders')
.on('connected', function(result){
assert(result) // First subscription
subscription.unsubscribe(); // Stop listening..
done();
});
});

it('resubscribes to an existing subscription', function(done){
this.timeout(5000);

Expand Down

0 comments on commit 9038a7a

Please sign in to comment.