Skip to content

mmujic/light-queue

Repository files navigation

light-queue

Build Status npm version install size Total alerts Language grade: JavaScript

Simple yet Powerful FIFO (First in, First out) Queue for Nodejs / Javascript

  • Zero dependencies
  • Simple and Powerful API
  • Lightweight

Use case:

  • Actual queue
  • Simple throttling (pop n number of items in interval)
  • Simple retry (if action fails return item to Queue)
  • ...

Install

$ npm install light-queue --save

Usage

const Queue = require('light-queue');

let queue = Queue();

queue.push(1);
let item = queue.pop();
console.log(item);              // 1

queue.push("Hello"); queue.push("world");
let items = queue.pop(2);
console.log(items.join(' '));   // Hello world

queue.push(100); queue.push(200); queue.push(300);
let all = queue.drain();
console.log(all.join(';'));     // 100;200;300

if (queue.isEmpty()) {
    queue.push(666);
}
console.log(queue.size());      // 1

queue.drain();
let sentence = 'I am gonna get there first because I came first.';
let words = sentence.split(' ');
queue = Queue(words);

let part = queue.pop(5);
console.log(part.join(' '));    // I am gonna get there