Skip to content

Commit f395c21

Browse files
apapirovskijasnell
authored andcommitted
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. PR-URL: #19936 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
1 parent 5135e24 commit f395c21

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+
const enrollObj = {
9+
_onTimeout: common.mustCall(),
10+
};
11+
12+
timers.enroll(enrollObj, 1);
13+
assert.strictEqual(enrollObj._idleTimeout, 1);
14+
timers.enroll(enrollObj, 10);
15+
assert.strictEqual(enrollObj._idleTimeout, 10);
16+
timers.active(enrollObj);

0 commit comments

Comments
 (0)