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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
31d6cec60e
commit
734eb17e5d
@ -353,13 +353,14 @@ exports.unenroll = util.deprecate(unenroll,
|
||||
// This function does not start the timer, see `active()`.
|
||||
// Using existing objects as timers slightly reduces object overhead.
|
||||
function enroll(item, msecs) {
|
||||
item._idleTimeout = validateTimerDuration(msecs);
|
||||
msecs = validateTimerDuration(msecs);
|
||||
|
||||
// if this item was already in a list somewhere
|
||||
// then we should unenroll it from that
|
||||
if (item._idleNext) unenroll(item);
|
||||
|
||||
L.init(item);
|
||||
item._idleTimeout = msecs;
|
||||
}
|
||||
|
||||
exports.enroll = util.deprecate(enroll,
|
||||
|
16
test/parallel/test-timers-enroll-second-time.js
Normal file
16
test/parallel/test-timers-enroll-second-time.js
Normal file
@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const timers = require('timers');
|
||||
|
||||
const enrollObj = {
|
||||
_onTimeout: common.mustCall(),
|
||||
};
|
||||
|
||||
timers.enroll(enrollObj, 1);
|
||||
assert.strictEqual(enrollObj._idleTimeout, 1);
|
||||
timers.enroll(enrollObj, 10);
|
||||
assert.strictEqual(enrollObj._idleTimeout, 10);
|
||||
timers.active(enrollObj);
|
Loading…
x
Reference in New Issue
Block a user