Skip to content

Commit 33ab12e

Browse files
committed
timers: fix refresh too early to exit
Add an or option for put refresh back to work. nodejs#26721 one reason it can't be overridden it only works in the callback of the current timer(before `finally`).
1 parent e0fa30f commit 33ab12e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/internal/timers.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ Timeout.prototype[inspect.custom] = function(_, options) {
190190
};
191191

192192
Timeout.prototype.refresh = function() {
193-
if (this[kRefed])
193+
// Timers that are active or have been invoked.
194+
if (this[kRefed] || this[kRefed] === null)
194195
active(this);
195196
else
196197
unrefActive(this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
// Check only timer reactivated by `.refresh()` is in loop,
6+
// only the timer is still active.
7+
8+
const timer = setTimeout(common.mustCall(() => {}, 2), 1);
9+
10+
setTimeout(() => {
11+
timer.refresh();
12+
}, 1);

0 commit comments

Comments
 (0)