Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 17 days ago
JSON representation

A lightweight circular queue for node.js

Awesome Lists containing this project

README

        

CircularQueue
===============================================================================

A lightweight circular queue, useful for situations where losing stale data is
preferable to unchecked memory growth.

[![Build
Status](https://travis-ci.org/rjz/circular-queue.svg)](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