diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2018-09-13 07:35:15 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-10-17 20:38:07 -0700 |
commit | e7af9830e98fcda7e7a11e0b13b667163cc8c940 (patch) | |
tree | bf90f7e9823fe29f90ea9b890ec39370a3e97526 /test/parallel/test-timers-next-tick.js | |
parent | 4e9e0d339efa46316d90d6f2618afd0c0fc6cd34 (diff) | |
download | android-node-v8-e7af9830e98fcda7e7a11e0b13b667163cc8c940.tar.gz android-node-v8-e7af9830e98fcda7e7a11e0b13b667163cc8c940.tar.bz2 android-node-v8-e7af9830e98fcda7e7a11e0b13b667163cc8c940.zip |
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>
Diffstat (limited to 'test/parallel/test-timers-next-tick.js')
-rw-r--r-- | test/parallel/test-timers-next-tick.js | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/test/parallel/test-timers-next-tick.js b/test/parallel/test-timers-next-tick.js index 1db1d18c3a..89ebf6c8c1 100644 --- a/test/parallel/test-timers-next-tick.js +++ b/test/parallel/test-timers-next-tick.js @@ -2,14 +2,29 @@ const common = require('../common'); -// This test documents an internal implementation detail of the Timers: -// since timers of different durations are stored in separate lists, -// a nextTick queue will clear after each list of timers. While this -// behaviour is not documented it could be relied on by Node's users. +// This test verifies that the next tick queue runs after each +// individual Timeout, as well as each individual Immediate. setTimeout(common.mustCall(() => { - process.nextTick(() => { clearTimeout(t2); }); + process.nextTick(() => { + // Confirm that clearing Timeouts from a next tick doesn't explode. + clearTimeout(t2); + clearTimeout(t3); + }); }), 1); -const t2 = setTimeout(common.mustNotCall(), 2); +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()); |