node/test/parallel/test-timers-refresh-in-callback.js
Anatoli Papirovski 4306300b5e timers: fix refresh inside callback
When `timers.refresh()` is called inside a callback, the timer would
incorrectly end up unrefed and thus not keep the event loop alive.

PR-URL: https://github.com/nodejs/node/pull/26721
Fixes: https://github.com/nodejs/node/issues/26642
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2019-03-20 07:21:58 +01:00

15 lines
321 B
JavaScript

'use strict';
const common = require('../common');
// This test checks whether a refresh called inside the callback will keep
// the event loop alive to run the timer again.
let didCall = false;
const timer = setTimeout(common.mustCall(() => {
if (!didCall) {
didCall = true;
timer.refresh();
}
}, 2), 1);