Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 41 lines (25 sloc) 1.827 kB
581e494 @mbostock Initial commit.
authored
1 # queue.js
2
8d98110 @jasondavies Add note about task arguments.
jasondavies authored
3 **Queue.js** is yet another asynchronous helper library for JavaScript. Think of it as a minimalist version of [Async.js](https://github.com/caolan/async) that allows fine-tuning over parallelism. Or, think of it as a version of [TameJs](http://tamejs.org/) that does not use code generation.
581e494 @mbostock Initial commit.
authored
4
7b75bf3 @mbostock Add another example.
authored
5 For example, if you wanted to stat two files in parallel:
581e494 @mbostock Initial commit.
authored
6
7 ```js
8 queue()
9 .defer(fs.stat, __dirname + "/../Makefile")
10 .defer(fs.stat, __dirname + "/../package.json")
11 .await(function(error, results) { console.log(results); });
12 ```
13
7b75bf3 @mbostock Add another example.
authored
14 Or, if you wanted to run a bazillion asynchronous tasks (here represented as an array of closures) serially:
15
16 ```js
17 var q = queue(1);
300e9f6 @mbostock Add forEach test.
authored
18 tasks.forEach(function(t) { q.defer(t); });
7b75bf3 @mbostock Add another example.
authored
19 q.await(function(error, results) { console.log("all done!"); });
20 ```
21
b4dd309 @mbostock Update README.
authored
22 Queue.js can be run inside Node.js or in a browser.
23
581e494 @mbostock Initial commit.
authored
24 ## API Reference
25
26 ### queue([parallelism])
27
b4dd309 @mbostock Update README.
authored
28 Constructs a new queue with the specified *parallelism*. If *parallelism* is not specified, 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.
581e494 @mbostock Initial commit.
authored
29
30 ### queue.defer(method[, arguments…])
31
8d98110 @jasondavies Add note about task arguments.
jasondavies authored
32 Adds the specified *method* to the queue, with any optional *arguments*. The *method* is called with the optional arguments and a final callback argument, which should be called when the task has finished.
581e494 @mbostock Initial commit.
authored
33
34 ### queue.await(callback)
35
36 Sets the *callback* to be notified when all deferred tasks have finished.
8d98110 @jasondavies Add note about task arguments.
jasondavies authored
37
38 ## Callbacks
39
40 The callbacks follow the Node.js convention where the first argument is an optional error object, and the second is used to pass on the result of an operation.
Something went wrong with that request. Please try again.