https://github.com/rjz/circular-queue
A lightweight circular queue for node.js
https://github.com/rjz/circular-queue
datastructures javascript queue ringbuffer
Last synced: 9 months ago
JSON representation
A lightweight circular queue for node.js
- Host: GitHub
- URL: https://github.com/rjz/circular-queue
- Owner: rjz
- License: other
- Created: 2015-06-27T21:26:34.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-08-10T03:51:35.000Z (over 10 years ago)
- Last Synced: 2025-03-26T16:38:41.832Z (10 months ago)
- Topics: datastructures, javascript, queue, ringbuffer
- Language: JavaScript
- Homepage: http://rjzaworski.com/2015/08/circular-queue
- Size: 121 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
CircularQueue
===============================================================================
A lightweight circular queue, useful for situations where losing stale data is
preferable to unchecked memory growth.
[](https://travis-ci.org/rjz/circular-queue)
Installation
-------------------------------------------------------------------------------
Clone this repository:
$ npm install circular-queue
Now, instantiate a queue with a fixed maximum size:
var CircularQueue = require('circular-queue');
var queue = new CircularQueue(10);
...`offer` it some items:
queue.offer('one');
queue.offer('two');
queue.offer('three');
...and `peek` at or `poll` them from the queue:
queue.peek(); // 'one'
queue.poll(); // 'one'
queue.peek(); // 'two'
### Events
Instances of `CircularQueue` will emit:
* `'evict'` - when stale items are evicted from the queue
Testing
-------------------------------------------------------------------------------
Lint and run test suite:
$ npm test
License
-------------------------------------------------------------------------------
MIT