Skip to content

Commit

Permalink
Merge pull request #140 from naugtur/abort-timeout
Browse files Browse the repository at this point in the history
Abort timeout, fixes #104
  • Loading branch information
naugtur authored Nov 12, 2016
2 parents 3791ed8 + 92f31b1 commit dc8f008
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ function _createXHR(options) {
xhr.onprogress = function () {
// IE must die
}
xhr.onabort = function(){
aborted = true;
}
xhr.ontimeout = errorFunc
xhr.open(method, uri, !sync, options.username, options.password)
//has to be after open
Expand All @@ -185,7 +188,8 @@ function _createXHR(options) {
// both npm's request and jquery 1.x use this kind of timeout, so this is being consistent
if (!sync && options.timeout > 0 ) {
timeoutTimer = setTimeout(function(){
aborted=true//IE9 may still call readystatechange
if (aborted) return
aborted = true//IE9 may still call readystatechange
xhr.abort("timeout")
var e = new Error("XMLHttpRequest timeout")
e.code = "ETIMEDOUT"
Expand Down

0 comments on commit dc8f008

Please sign in to comment.