Registry / storage / reactive-circular-queue

reactive-circular-queue

JSON →
library3.0.0jsnpmunverified

A circular queue (ring buffer) implementation with reactive state stores (ReadonlyStore). Current stable version: 3.0.0. Released as a single npm package with TypeScript types, ESM-only distribution, and Node.js >=20 requirement. Differentiates from other circular queue libraries by providing reactive observables for availableSlots, filledSlots, full, and empty states, enabling reactive programming patterns without polling or callbacks. Includes Symbol.iterator support and methods like enqueueMulti, dequeueAll, at, replace, and remove.

npm install reactive-circular-queue
INSTALL
IMPORT
SIG · REACTIVE-CIRCULAR-
R
reactive-circular-queue
storagejavascriptv3.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

makeCircularQueue
import { makeCircularQueue } from 'reactive-circular-queue'
const makeCircularQueue = require('reactive-circular-queue')
ESM-only since v3. CommonJS require will fail because the package does not provide a CJS export. TypeScript types are included.
CircularQueue
import { makeCircularQueue } from 'reactive-circular-queue'; const queue = makeCircularQueue<number>(5)
import { CircularQueue } from 'reactive-circular-queue'
CircularQueue is a type (interface) only, not a constructor. Use makeCircularQueue to create instances.
ReadonlyStore
import type { ReadonlyStore } from 'universal-stores'
import { ReadonlyStore } from 'universal-stores'
ReadonlyStore is a type only. Import as type to avoid runtime errors. It is re-exported from reactive-circular-queue? No, it is from a peer dependency.

Shows creating a queue, enqueuing, dequeuing, reactive store access, iteration via Symbol.iterator, and conversion to array.

import { makeCircularQueue } from 'reactive-circular-queue'; // Create a queue with capacity 3 const queue = makeCircularQueue<string>(3); // Enqueue items queue.enqueue('a'); queue.enqueue('b'); queue.enqueue('c'); // Dequeue items (FIFO order) console.log(queue.dequeue()); // 'a' console.log(queue.dequeue()); // 'b' // Check reactive stores console.log(queue.filledSlots$.content()); // 1 console.log(queue.availableSlots$.content()); // 2 // Enqueue more queue.enqueue('d'); queue.enqueue('e'); // This might overflow? Check behavior: depends on capacity, but queue is not resizable // Use iterator for (const item of queue) { console.log(item); } // Convert to array console.log(queue.toArray()); // ['c', 'd', 'e']
Debug
Known issues
breakingMigration from v2 to v3: require() no longer works; use ESM import.
fix
Replace const X = require('reactive-circular-queue') with import { makeCircularQueue } from 'reactive-circular-queue'
affects: >=3.0.0 <4.0.0
breakingNode.js version requirement increased to >=20 in v3.
fix
Upgrade Node.js to version 20 or later.
affects: >=3.0.0
deprecatedv2 is deprecated and no longer maintained.
fix
Upgrade to v3 and switch to ESM imports.
affects: >=2.0.0 <3.0.0
gotchaCircularQueue does not extend Array or implement all array methods; cannot use .map(), .filter(), etc.
fix
Use toArray() first, then chain array methods. For reactive manipulation, use universal-stores transformers.
affects: >=3.0.0
gotchaenqueue() may silently ignore items when the queue is full? Actually, check implementation: it throws? No, v3 likely does not allow overflow; check docs: 'enqueue' adds if slots available; otherwise? Not specified. Assume it may throw or be ignored.
fix
Check full$ store before enqueueing, or use enqueueMulti which may behave differently.
affects: >=3.0.0
Errors
Common errors & fixes
Cannot find module 'reactive-circular-queue'
Package not installed or incorrect import path.
fix
Run npm install reactive-circular-queue and ensure using ESM import syntax.
makeCircularQueue is not a function
Using CommonJS require() on an ESM-only package.
fix
Change to import { makeCircularQueue } from 'reactive-circular-queue' and ensure project uses ESM (set type: module in package.json).
TypeError: queue.enqueue is not a function
Trying to use CircularQueue as a constructor or importing incorrectly.
fix
Use makeCircularQueue() to create the instance, then call methods on that instance.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
universal-storesoptionalProvides the ReadonlyStore type used for reactive state properties (availableSlots$, filledSlots$, full$, empty$).
Agent activity
29 hits · last 30 days
node
28
Resources
reactive-circular-queue — npm install reactive-circular-queue · libregistry