Skip to content

Commit c402d77

Browse files
authoredMar 6, 2020
Stop retry timer with operation.stop() (#69)
Fix tim-kos/node-retry/#64
1 parent 2424324 commit c402d77

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎lib/retry_operation.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function RetryOperation(timeouts, options) {
1515
this._operationTimeoutCb = null;
1616
this._timeout = null;
1717
this._operationStart = null;
18+
this._timer = null;
1819

1920
if (this._options.forever) {
2021
this._cachedTimeouts = this._timeouts.slice(0);
@@ -31,6 +32,9 @@ RetryOperation.prototype.stop = function() {
3132
if (this._timeout) {
3233
clearTimeout(this._timeout);
3334
}
35+
if (this._timer) {
36+
clearTimeout(this._timer);
37+
}
3438

3539
this._timeouts = [];
3640
this._cachedTimeouts = null;
@@ -65,7 +69,7 @@ RetryOperation.prototype.retry = function(err) {
6569
}
6670

6771
var self = this;
68-
var timer = setTimeout(function() {
72+
this._timer = setTimeout(function() {
6973
self._attempts++;
7074

7175
if (self._operationTimeoutCb) {
@@ -82,7 +86,7 @@ RetryOperation.prototype.retry = function(err) {
8286
}, timeout);
8387

8488
if (this._options.unref) {
85-
timer.unref();
89+
this._timer.unref();
8690
}
8791

8892
return true;

0 commit comments

Comments
 (0)
Please sign in to comment.