bb-queue
v1.1.0
Published
A simple, automated queue processor
Downloads
5
Maintainers
Readme
A simple, automated queue processor
How to install
npm install bb-queue
How to use
var BBQ = require('bb-queue');
var bbq = new BBQ(callback, { options }, context);
Syncronous Processing
If a second parameter is defined on the callback, calling that parameter as a function will cause the queue to advance to the next item.
var bbq = new BBQ(function(item, next) {
process(function() {
console.log(item);
next();
});
});
Examples
/*
* Queue is immediately monitored upon instantiation. Each object of the
* queue is passed into the callback for processing one at a time.
*/
var BBQ = require('bb-queue');
var bbq = new BBQ(function(ingredient) {
console.log(ingredient);
});
bbq.add('bread');
bbq.add('lettace');
// You can pass multiple items in one call to add()
bbq.add('mustard', 'onion', 'bacon');
/*
* Will print...
* bread
* lettace
* mustard
* onion
* bacon
*/
bbq.stop(); // Stop/Pause processing
bbq.add('cat'); // oops
bbq.clear(); // Clear queue
bbq.add('turkey', 'ham');
bbq.resume(); // Resume processing
bbq.stop(); // Don't leave the queue processing if re-assigning
bbq = new BBQ(function(color) {
console.log(color);
}, { lifo: true });
bbq.add('red', 'green', 'purple');
/*
* Prints...
* purple
* green
* red
*/
Change Log
1.0.0
- First release