1.0.0 • Published 9 years ago

another-queue v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

another-queue

Function queue implementation for Node.js

Installation

$ npm install another-queue

Usage

var Queue = require('another-queue'),
    q = new Queue(options);

q.push(function (a, b, c) {
    console.log(a);
    console.log(b);
    console.log(c);
}, [1, 2, 3]);

q.start();

'options' object

  • max - maximum queue length (default - null)
  • delay - interval in milliseconds (default - 200)
  • stopOnEmpty - stop the timer (default - false)

Methods

1.push

Add new element to the queue

var id = q.push(function[, arguments[, context]]);

Arguments:

function - function to execute

arguments - arguments array

context - 'this' argument for this function

so, it's like Function.apply()

Returns:

id - string identifier of this queue element

2.start

Start the queue

q.start()

3.stop

Stop the queue

q.stop()

Events

  • start - on queue start
  • stop - on stop
  • execute - on element's function call
  • overflow - on queue overflow (only if max option was set)
q.on('start', function () {
    console.log('queue started');
});
q.on('stop', function () {
    console.log('queue stopped');
});
q.on('execute', function (id) {
    console.log('function with id=' + id + ' executed');
});
q.on('overflow', function () {
    console.log('WARNING: queue overflow');
});
1.0.0

9 years ago