node/test/parallel/test-timers-next-tick.js
Anatoli Papirovski e7af9830e9 timers: run nextTicks after each immediate and timer
In order to better match the browser behaviour, run nextTicks (and
subsequently the microtask queue) after each individual Timer and
Immediate, rather than after the whole list is processed. The
current behaviour is somewhat of a performance micro-optimization
and also partly dictated by how timer handles were implemented.

PR-URL: https://github.com/nodejs/node/pull/22842
Fixes: https://github.com/nodejs/node/issues/22257
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-10-17 20:38:07 -07:00

31 lines
846 B
JavaScript

'use strict';
const common = require('../common');
// This test verifies that the next tick queue runs after each
// individual Timeout, as well as each individual Immediate.
setTimeout(common.mustCall(() => {
process.nextTick(() => {
// Confirm that clearing Timeouts from a next tick doesn't explode.
clearTimeout(t2);
clearTimeout(t3);
});
}), 1);
const t2 = setTimeout(common.mustNotCall(), 1);
const t3 = setTimeout(common.mustNotCall(), 1);
setTimeout(common.mustCall(), 1);
common.busyLoop(5);
setImmediate(common.mustCall(() => {
process.nextTick(() => {
// Confirm that clearing Immediates from a next tick doesn't explode.
clearImmediate(i2);
clearImmediate(i3);
});
}));
const i2 = setImmediate(common.mustNotCall());
const i3 = setImmediate(common.mustNotCall());
setImmediate(common.mustCall());