async-waterfall
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -5,3 +5,3 @@ { | ||
"description": "Runs a list of async tasks, passing the results of each into the next one", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"keywords": ["async", "waterfall", "tasks", "control", "flow"], | ||
@@ -8,0 +8,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ { | ||
"description": "Runs a list of async tasks, passing the results of each into the next one", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"keywords": ["async", "waterfall", "tasks", "control", "flow"], | ||
@@ -8,0 +8,0 @@ "main": "index.js", |
@@ -30,6 +30,10 @@ // MIT license (by Elan Shanker). | ||
}; | ||
var _isArray = Array.isArray || function(maybeArray){ | ||
return Object.prototype.toString.call(maybeArray) === "[object Array]"; | ||
}; | ||
var waterfall = function (tasks, callback) { | ||
callback = callback || function () {}; | ||
if (tasks.constructor !== Array) { | ||
if (!_isArray(tasks)) { | ||
var err = new Error('First argument to waterfall must be an array of functions'); | ||
@@ -36,0 +40,0 @@ return callback(err); |
{ | ||
"name": "async-waterfall", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Runs a list of async tasks, passing the results of each into the next one", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -30,6 +30,23 @@ # async-waterfall | ||
#### Node.js: | ||
##### Node.js: | ||
```javascript | ||
var waterfall = require('async-waterfall'); | ||
waterfall(tasks, callback); | ||
``` | ||
##### Browser: | ||
```javascript | ||
// component(1) | ||
var waterfall = require('async-waterfall'); | ||
waterfall(tasks, callback); | ||
// Default: | ||
window.asyncWaterfall(tasks, callback); | ||
``` | ||
##### Tasks as Array of Functions | ||
```javascript | ||
waterfall([ | ||
@@ -51,13 +68,17 @@ function(callback){ | ||
#### Browser: | ||
##### Derive Tasks from an Array.map | ||
```javascript | ||
// component(1) | ||
var waterfall = require('async-waterfall'); | ||
waterfall(tasks, callback); | ||
// Default: | ||
window.asyncWaterfall(tasks, callback); | ||
waterfall(myArray.map(function (arrayItem) { | ||
return function (lastItemResult, nextCallback) { | ||
// same execution for each item in the array | ||
var itemResult = doThingsWith(arrayItem, lastItemResult); | ||
// results carried along from each to the next | ||
nextCallback(null, itemResult); | ||
}}), function (err, result) { | ||
// final callback | ||
}); | ||
``` | ||
## Acknowledgements | ||
@@ -64,0 +85,0 @@ Hat tip to [Caolan McMahon](https://github.com/caolan) and |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7065
95
111