Yet another asynchronous helper library for JavaScript. 553 bytes!
JavaScript
Switch branches/tags
Nothing to show
Pull request Compare This branch is 11 commits ahead, 160 commits behind d3:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
LICENSE
Makefile
README.md
package.json
queue.js
queue.min.js

README.md

queue.js, Overcomplicated

This is a folk of mbostock's queue.js that vastly overcomplicates the original module by requiring you to explicitly state where the callback argument is supposed to go

Queue.js is yet another asynchronous helper library for JavaScript. Think of it as a minimalist version of Async.js that allows fine-tuning over parallelism. Or, think of it as a version of TameJs that does not use code generation.

For example, if you wanted to stat two files in parallel:

queue()
    .defer(fs.stat, __dirname + "/../Makefile", queue.D)
    .defer(fs.stat, __dirname + "/../package.json", queue.D)
    .defer(setTimeout, queue.D, 3000)
    .await(function(error, results) { console.log(results); });

Or, if you wanted to run a bazillion asynchronous tasks (here represented as an array of closures) serially:

var q = queue(1);
tasks.forEach(function(t) { q.defer(t, queue.D); });
q.await(function(error, results) { console.log("all done!"); });

Queue.js can be run inside Node.js or in a browser.

API Reference

queue([parallelism])

Constructs a new queue with the specified parallelism. If parallelism is not specified or is 0, the queue has infinite parallelism. Otherwise, parallelism is a positive integer. For example, if parallelism is 1, then all tasks will be run in series. If parallelism is 3, then at most three tasks will be allowed to proceed concurrently; this is useful, for example, when loading resources in a web browser.

queue.defer(method[, arguments…])

Adds the specified method to the queue, with any optional arguments. Use queue.D for the callback argument.

queue.await(callback)

Sets the callback to be notified when all deferred tasks have finished.