2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-12-24 01:02:12 +01:00
|
|
|
require('../common');
|
2016-12-31 00:38:06 +01:00
|
|
|
const assert = require('assert');
|
2013-07-12 01:04:49 +02:00
|
|
|
|
|
|
|
// setImmediate should run clear its queued cbs once per event loop turn
|
|
|
|
// but immediates queued while processing the current queue should happen
|
|
|
|
// on the next turn of the event loop.
|
|
|
|
|
2016-12-29 17:55:51 +01:00
|
|
|
// hit should be the exact same size of QUEUE, if we're letting things
|
|
|
|
// recursively add to the immediate QUEUE hit will be > QUEUE
|
2013-07-12 01:04:49 +02:00
|
|
|
|
2016-12-29 17:55:51 +01:00
|
|
|
let ticked = false;
|
2013-07-12 01:04:49 +02:00
|
|
|
|
2016-12-29 17:55:51 +01:00
|
|
|
let hit = 0;
|
|
|
|
const QUEUE = 1000;
|
2013-07-12 01:04:49 +02:00
|
|
|
|
|
|
|
function run() {
|
|
|
|
if (hit === 0)
|
|
|
|
process.nextTick(function() { ticked = true; });
|
|
|
|
|
|
|
|
if (ticked) return;
|
|
|
|
|
|
|
|
hit += 1;
|
|
|
|
setImmediate(run);
|
|
|
|
}
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < QUEUE; i++)
|
2013-07-12 01:04:49 +02:00
|
|
|
setImmediate(run);
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
console.log('hit', hit);
|
|
|
|
assert.strictEqual(hit, QUEUE, 'We ticked between the immediate queue');
|
|
|
|
});
|