Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
timers: fix refresh too early to exit
Add an or option for put refresh back to work. #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
commit 33ab12eaab6ee6e976a1169c2045da62372a5ddd
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);