Skip to content
Browse files

Fixed readme extension. For real this time.

  • Loading branch information...
1 parent e0264be commit f4e1df378ea8e5c934bb3d671f0a63898576fe84 @alexkwolfe committed Aug 11, 2010
Showing with 61 additions and 0 deletions.
  1. +61 −0 README.md
View
61 README.md
@@ -0,0 +1,61 @@
+# Gang Bang
+
+A flow control library for node.js for executing multiple functions as a group or in a chain, calling back when all functions have finished.
+
+## Installation
+
+ npm install gang-bang
+
+## Usage
+
+ var gang = require('gang-bang'),
+ puts = require('sys').puts;
+
+ // the array of functions to execute. each calls the done function
+ // upon completion, passing back relevant information.
+ var functions = [
+ function(done) { done('red'); },
+ function(done) { done('green'); },
+ function(done) { done('blue'); }
+ ];
+
+ // execute functions concurrently, and callback when all functions have been called
+ gang.group(functions, function(colors) {
+ puts("All colors were collected: " + colors);
+ });
+
+ // execute each one after the other, and callback when all functions have been called
+ gang.chain(functions, function(colors) {
+ puts("All colors were collected: " + colors);
+ });
+
+## Error handling
+
+If an error occurs in a function, pass the error to the `done` method. The error will be included
+among the values passed to the callback function.
+
+When an error occurs during chained execution, the chain stops and the values collected (including
+the error) are returned to the callback function.
+
+Check for errors in the values passed to the callback function and behave accordingly.
+
+ var gang = require('gang-bang'),
+ puts = require('sys').puts;
+
+ // the array of functions to execute. each calls the done function
+ // upon completion, passing back relevant information.
+ var functions = [
+ function(done) { done('red'); },
+ function(done) { done(new Error('something went wrong')); },
+ function(done) { done('blue'); }
+ ];
+
+ // execute functions concurrently, and callback when all functions have been called
+ gang.group(functions, function(colors) {
+ puts("Two colors and one error were collected: " + colors);
+ });
+
+ // execute each one after the other, and callback when the error occurrs
+ gang.chain(functions, function(colors) {
+ puts("One color and one error were collected: " + colors);
+ });

0 comments on commit f4e1df3

Please sign in to comment.
Something went wrong with that request. Please try again.