asynchronous function queue with adjustable concurrency
____ __ _____ __ _____/ __ `/ / / / _ \/ / / / _ \/ /_/ / /_/ / __/ /_/ / __/\__, /\__,_/\___/\__,_/\___//_/
Asynchronous function queue with adjustable concurrency.
Async is a big library offering various approaches to dealing with asynchrony;
queue is a small library offering a single, flexible abstraction.
This module exports a class
Queue that implements most of the
Array API. Pass async functions (ones that accept a callback) to an instance's additive array methods. Processing begins when you call
npm install queue
npm run test-browser
npm run example
var queue = require'queue';var q = queue;var results = ;// add jobs using the Array APIqpushresultspush'two';cb;;qpushresultspush'four';cb;resultspush'five';cb;;qunshiftresultspush'one';cb;;qsplice2 0resultspush'three';cb;;// use the timeout feature to deal with jobs that// take too long or forget to execute a callbackqtimeout = 100;qon'timeout'console.log'job timed out:' jobtoStringreplace/\n/g '';next;;qpushsetTimeoutconsole.log'slow job finished';cb;200;;qpushconsole.log'forgot to execute callback';;// get notified when jobs completeqon'success'console.log'job finished processing:' jobtoStringreplace/\n/g '';;// begin processing, get notified on end / failureqstartconsole.log'all done:' results;;
opts may contain inital values for:
cb, if passed, will be called when the queue empties or when an error occurs.
Stops the queue. can be resumed with
Stop and empty the queue immediately.
Mozilla has docs on how these methods work here.
Max number of jobs the queue should process concurrently, defaults to
Milliseconds to wait for a job to execute its callback.
Jobs pending + jobs to process (readonly).
After a job executes its callback.
After a job passes an error to its callback.
q.timeout milliseconds have elapsed and a job has not executed its callback.
After all jobs have been processed
The latest stable release is published to npm. Abbreviated changelog below:
- Add .npmignore
- Change the default concurrency to
q.start()to accept an optional callback executed on
- Major api changes / not backwards compatible with 1.x
- Early prototype
Copyright © 2014 Jesse Tane firstname.lastname@example.org
This work is free. You can redistribute it and/or modify it under the terms of the WTFPL.
No Warranty. The Software is provided "as is" without warranty of any kind, either express or implied, including without limitation any implied warranties of condition, uninterrupted use, merchantability, fitness for a particular purpose, or non-infringement.