co-queue
A FIFO queue for co.
Example
Create a queue with one producer and two consumers doing fake work:
var Queue = ;var co = ;var wait = ; var queue = ; ; ; ;
The output is:
$ make exampleconsumer 1: 0.4872316620312631consumer 2: 0.8702194727957249consumer 1: 0.200025983620435consumer 2: 0.14811497158370912consumer 2: 0.6677501150406897consumer 1: 0.5147413061931729consumer 2: 0.6373226766008884consumer 1: 0.5006165818776935consumer 2: 0.15247466461732984consumer 2: 0.9118324755690992^C
Installation
You need to run node 0.11.x
or higher and add the --harmony
flag.
$ npm install co-queue
API
Queue()
Create a new FIFO queue.
Queue#push(data)
Push data
onto the queue.
Queue#push
is bound to the queue, so hooking into existing libraries is easy:
emitter;stream;;
Queue#next()
Get the next piece of data.
Queue#max(max)
Set the maximum buffer size. When reached, new data will be dropped.
Queue#events.on('overflow', fn)
The overflow
event will be emitted whenever data is dropped, which will be passed to fn
as first argument.
License
MIT