operation-queue
v1.0.1
Published
Cancellable, async serial function execution
Downloads
4
Maintainers
Readme
operation-queue
Queue asynchronous operations for serial execution with optional completion callbacks. At any point the queue can be cancelled. When cancelled, the queue will a) wait for any pending operation to complete and b) fire the callbacks of all other pending jobs, indicating that they were cancelled. Any new operation added to a cancelled queue will also receive an asynchronous callback indicating that it was cancelled.
API
var OperationQueue = require('operation-queue');
var queue = new OperationQueue()
Create a new operation queue.
queue.push(fn, [cb])
Enqueue operation fn
, optionally calling cb
on completion. fn
will receive a single callback as an argument that you must call to indicate that the opearation is complete; any arguments will be forwarded to your own callback.
queue.close([cb])
Close the queue, optionally calling cb
when the close operation is complete, by first waiting for any in-progress operation to complete. Any further remaining items in the queue will have their callbacks invoked with the value OperaionQueue.CANCELLED
.
License
ISC