A simple queue with asynchronous pop()
A Queue with a callback driven
pop() are relatively normal,
pop() instead takes a callback and is called whenever there is an item available.
It's ideal for creating a work-queue where each worker needs to process one item at a time and should be notified when new items are added.
var NotifyQueue = require'notify-queue';var q = ;qpop// do some stuff with item.;qpush"an item";
var NotifyQueue = require'notify-queue';var q = ;var cancel = qpop// do some stuff with item.;cancel;qpush"an item"; // the callback above won't be called
pop() call can be called multiple times if next() is used:
var NotifyQueue = require'notify-queue';var q = ;qpopsomeasyncfunctionitemnext;;;qpush"an item";qpush"another item";
Or, with matchers:
var NotifyQueue = require'notify-queue';var q = ;// only called when item.isForMe == true;return itemisForMe == true;qpopprocessor matcherqpush"an item";qpushisForMe: true msg: "an item";
Adds an item to the queue triggering any waiting
callback so it's called whenever an item is added to the queue.
matcher function is provided,
callback will only be called when
matcher(item) returns something truthy.
callback will be called for the first item.
callback is passed the item and a
callback will not be called again unless
next() is called.
pop() is called more than once,
available callbacks will be served items in a round-robin fashion.
An available callback is one that is not waiting for
next() to be called.
pop() returns a function that when called, removes the
callback from the
list of waiting callbacks and ensures it will not be called again.
Returns the array of items currently in the queue. This is the internal representation and can be modified as necessary to remove or rearrange items.