Skip to content

Commit

Permalink
change after review
Browse files Browse the repository at this point in the history
  • Loading branch information
eromano committed May 18, 2018
1 parent 650b521 commit 03e5efa
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,17 @@ Request.prototype.end = function(fn){
return this._end();
};

Request.prototype._setUploadTimeout = function () {
const self = this;

// upload timeout it's wokrs only if deadline timeout is off
if (this._uploadTimeout && !this._uploadTimeoutTimer) {
this._uploadTimeoutTimer = setTimeout(() => {
self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT');
}, this._uploadTimeout);
}
};

Request.prototype._end = function() {
if (this._aborted) return this.callback(Error("The request has been aborted even before .end() was called"));

Expand Down Expand Up @@ -710,10 +721,12 @@ Request.prototype._end = function() {
// progress
const handleProgress = (direction, e) => {

clearTimeout(self._uploadTimeoutTimer);
if (e.total > 0) {
e.percent = e.loaded / e.total * 100;
} else if(e.total = 100){
clearTimeout(self._uploadTimeoutTimer);
}

e.direction = direction;
self.emit('progress', e);
};
Expand All @@ -731,12 +744,7 @@ Request.prototype._end = function() {
}

if(xhr.upload){
// upload timeout it's wokrs only if deadline timeout is off
if (this._uploadTimeout && !this._uploadTimeoutTimer) {
this._uploadTimeoutTimer = setTimeout(() => {
self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT');
}, this._uploadTimeout);
}
this._setUploadTimeout();
}

// initiate request
Expand Down

0 comments on commit 03e5efa

Please sign in to comment.