mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 13:47:16 +00:00

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>
31 lines
846 B
JavaScript
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());
|