diff options
author | Andrés Aldana <andres.aldana.martinez@gmail.com> | 2016-06-30 22:34:38 -0500 |
---|---|---|
committer | Andrés Aldana <andres.aldana.martinez@gmail.com> | 2016-06-30 22:34:38 -0500 |
commit | 3b5b1505778ccaf30fbd933b248a0906d1fdd97d (patch) | |
tree | e5bb13215a68fb495dc3e0e51dc9ddcffcfb1194 | |
parent | 2564a54efc7bd97cf4ff0b8629ecda66741a1142 (diff) | |
download | async-3b5b1505778ccaf30fbd933b248a0906d1fdd97d.tar.gz |
Add object of tasks documentation
-rw-r--r-- | lib/reflectAll.js | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/reflectAll.js b/lib/reflectAll.js index d1ad247..29d6106 100644 --- a/lib/reflectAll.js +++ b/lib/reflectAll.js @@ -2,7 +2,7 @@ import reflect from './reflect'; import isArray from 'lodash/isArray'; /** - * A helper function that wraps an array of functions with reflect. + * A helper function that wraps an array or an object of functions with reflect. * * @name reflectAll * @static @@ -39,6 +39,32 @@ import isArray from 'lodash/isArray'; * // results[1].error = Error('bad stuff happened') * // results[2].value = 'two' * }); + * + * // an example using an object instead of an array + * let tasks = { + * one: function(callback) { + * setTimeout(function() { + * callback(null, 'one'); + * }, 200); + * }, + * two: function(callback) { + * callback('two'); + * }, + * three: function(callback) { + * setTimeout(function() { + * callback(null, 'three'); + * }, 100); + * } + * }; + * + * async.parallel(async.reflectAll(tasks), + * // optional callback + * function(err, results) { + * // values + * // results.one.value = 'one' + * // results.two.error = 'two' + * // results.three.value = 'three' + * }); */ export default function reflectAll(tasks) { var results; @@ -48,7 +74,7 @@ export default function reflectAll(tasks) { var keys = Object.keys(tasks); results = {}; keys.forEach(function(key) { - results[key] = reflect.call(this, tasks[key]) + results[key] = reflect.call(this, tasks[key]); }); } return results; |