summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrés Aldana <andres.aldana.martinez@gmail.com>2016-06-30 22:34:38 -0500
committerAndrés Aldana <andres.aldana.martinez@gmail.com>2016-06-30 22:34:38 -0500
commit3b5b1505778ccaf30fbd933b248a0906d1fdd97d (patch)
treee5bb13215a68fb495dc3e0e51dc9ddcffcfb1194
parent2564a54efc7bd97cf4ff0b8629ecda66741a1142 (diff)
downloadasync-3b5b1505778ccaf30fbd933b248a0906d1fdd97d.tar.gz
Add object of tasks documentation
-rw-r--r--lib/reflectAll.js30
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;