Skip to content

Commit

Permalink
Add configurable timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgq committed Jun 26, 2014
1 parent 4f59db0 commit 910315c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions corsRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@

this.req.open(this.method, this.url);

this.req.ontimeout = function() {
self.err = error('timeout');
done(self.err);
};

this.req.onerror = function() {
self.err = error('error');
done(self.err);
Expand All @@ -138,9 +133,10 @@
done(self.err, self.res);
};

// Setting this handler seems to increase the probability
// Setting all handlers seems to increase the probability
// of the request being sucessful on old IE versions.
if (useXdr) {
this.req.ontimeout = noop;
this.req.onprogress = noop;
}

Expand All @@ -163,6 +159,17 @@
self.req.send(payload || null);
}
}, 0);

// Perform our own timeout logic instead of relying on
// the underlying implementation.
if (corsRequest.timeout > 0) {
setTimeout(function() {
if (self.err === void 0) {
self.err = error('timeout');
done(self.err);
}
}, corsRequest.timeout);
}
}


Expand Down Expand Up @@ -203,6 +210,10 @@
}


// Default timeout value.
corsRequest.timeout = 0;


// Report implementation in use.
corsRequest.usingXhr = useXhr;
corsRequest.usingXdr = useXdr;
Expand Down

0 comments on commit 910315c

Please sign in to comment.