mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
9a3ae2fe9d
A bug was introduced together with the FixedQueue implementation for process.nextTick which meant that the queue wouldn't necessarily fully clear on each run through. Fix it and abstract the data structure into an internal module that can later be used elsewhere. PR-URL: https://github.com/nodejs/node/pull/20468 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
35 lines
842 B
JavaScript
35 lines
842 B
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
const FixedQueue = require('internal/fixed_queue');
|
|
|
|
{
|
|
const queue = new FixedQueue();
|
|
assert.strictEqual(queue.head, queue.tail);
|
|
assert(queue.isEmpty());
|
|
queue.push('a');
|
|
assert(!queue.isEmpty());
|
|
assert.strictEqual(queue.shift(), 'a');
|
|
assert.strictEqual(queue.shift(), null);
|
|
}
|
|
|
|
{
|
|
const queue = new FixedQueue();
|
|
for (let i = 0; i < 2047; i++)
|
|
queue.push('a');
|
|
assert(queue.head.isFull());
|
|
queue.push('a');
|
|
assert(!queue.head.isFull());
|
|
|
|
assert.notStrictEqual(queue.head, queue.tail);
|
|
for (let i = 0; i < 2047; i++)
|
|
assert.strictEqual(queue.shift(), 'a');
|
|
assert.strictEqual(queue.head, queue.tail);
|
|
assert(!queue.isEmpty());
|
|
assert.strictEqual(queue.shift(), 'a');
|
|
assert(queue.isEmpty());
|
|
}
|