Skip to content

Commit

Permalink
timers: fix refresh too early to exit
Browse files Browse the repository at this point in the history
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`).
  • Loading branch information
zero1five committed Jun 13, 2019
1 parent e0fa30f commit 33ab12e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ Timeout.prototype[inspect.custom] = function(_, options) {
};

Timeout.prototype.refresh = function() {
if (this[kRefed])
// Timers that are active or have been invoked.
if (this[kRefed] || this[kRefed] === null)
active(this);
else
unrefActive(this);
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-timers-refresh-called.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const common = require('../common');

// Check only timer reactivated by `.refresh()` is in loop,
// only the timer is still active.

const timer = setTimeout(common.mustCall(() => {}, 2), 1);

setTimeout(() => {
timer.refresh();
}, 1);

0 comments on commit 33ab12e

Please sign in to comment.