Skip to content

Commit e838531

Browse files
committed
timers: fix subsequent enroll calls not working
A bug was introduced in #17704 which meant that subsequent calls to enroll would unset the new _idleTimeout and the enrolled object could never again function as a timer.
1 parent fa2d43b commit e838531

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/timers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,14 @@ exports.unenroll = util.deprecate(unenroll,
353353
// This function does not start the timer, see `active()`.
354354
// Using existing objects as timers slightly reduces object overhead.
355355
function enroll(item, msecs) {
356-
item._idleTimeout = validateTimerDuration(msecs);
356+
msecs = validateTimerDuration(msecs);
357357

358358
// if this item was already in a list somewhere
359359
// then we should unenroll it from that
360360
if (item._idleNext) unenroll(item);
361361

362362
L.init(item);
363+
item._idleTimeout = msecs;
363364
}
364365

365366
exports.enroll = util.deprecate(enroll,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const assert = require('assert');
6+
const timers = require('timers');
7+
8+
let didCall = false;
9+
const enrollObj = {
10+
_onTimeout: common.mustCall(() => assert(didCall)),
11+
};
12+
13+
timers.enroll(enrollObj, 1);
14+
timers.enroll(enrollObj, 10);
15+
timers.active(enrollObj);
16+
setTimeout(common.mustCall(() => { didCall = true; }), 1);

0 commit comments

Comments
 (0)