nodejs/test/parallel/test-timers-next-tick.js

33 lines
909 B
JavaScript
Raw Normal View History

2022-08-16 11:12:47 +08:00
// Flags: --expose-internals
'use strict';
const common = require('../common');
const { sleep } = require('internal/util');
// 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);
sleep(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());