Skip to content

Commit b43d2dd

Browse files
Fishrock123BridgeAR
authored andcommitted
timers: set _destroyed even if there are no destroy-hooks
Required for other potential changes. This should make it so we can always just check _destroyed to check if a timer has been ended. PR-URL: #29595 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 322bc6f commit b43d2dd

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

lib/internal/timers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ function getTimerCallbacks(runNextTicks) {
544544

545545
if (destroyHooksExist() && !timer._destroyed) {
546546
emitDestroy(timer[async_id_symbol]);
547-
timer._destroyed = true;
548547
}
548+
timer._destroyed = true;
549549
}
550550
}
551551

lib/timers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ function unenroll(item) {
6565
item[async_id_symbol] !== undefined &&
6666
!item._destroyed) {
6767
emitDestroy(item[async_id_symbol]);
68-
item._destroyed = true;
6968
}
69+
item._destroyed = true;
7070

7171
L.remove(item);
7272

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
6+
// We don't really care about the calling results here.
7+
// So, this makes the test less fragile.
8+
const noop = () => {};
9+
10+
const t1 = setTimeout(common.mustNotCall(), 1);
11+
const t2 = setTimeout(common.mustCall(), 1);
12+
const i1 = setInterval(common.mustNotCall(), 1);
13+
const i2 = setInterval(noop, 1);
14+
i2.unref();
15+
16+
// Keep process alive for i2 to call once due to timer ordering.
17+
setTimeout(common.mustCall(), 1);
18+
19+
clearTimeout(t1);
20+
clearInterval(i1);
21+
22+
process.on('exit', () => {
23+
assert.strictEqual(t1._destroyed, true);
24+
assert.strictEqual(t2._destroyed, true);
25+
assert.strictEqual(i1._destroyed, true);
26+
assert.strictEqual(i2._destroyed, false);
27+
});

0 commit comments

Comments
 (0)