Skip to content

Commit

Permalink
resend request in case server was disconnected after request was sent
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdarkdragon committed Sep 8, 2015
1 parent 50acc4c commit c57cef4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,20 @@ Request.prototype.callback = function(callback, successEvent, errorEvent) {

let called = false;

function onReconnect() {
self.remote.request(self);
}

function requestSuccess(message) {
self.remote.removeListener('connected', onReconnect);
if (!called) {
called = true;
callback.call(self, null, message);
}
}

function requestError(error) {
self.remote.removeListener('connected', onReconnect);
if (!called) {
called = true;

Expand All @@ -228,6 +234,9 @@ Request.prototype.callback = function(callback, successEvent, errorEvent) {

this.once(this.successEvent, requestSuccess);
this.once(this.errorEvent, requestError);
if (this.remote.isConnected()) {
this.remote.once('connected', onReconnect);
}
this.request();

return this;
Expand Down

0 comments on commit c57cef4

Please sign in to comment.