summaryrefslogtreecommitdiff
path: root/docs/v3/series.js.html
diff options
context:
space:
mode:
authorRoman Lorenzo Balayan <roman.balayan@gmail.com>2021-08-06 06:58:10 +0800
committerGitHub <noreply@github.com>2021-08-05 15:58:10 -0700
commit159a119fbb1a585c61f33b4b3b5036f5d332ebbb (patch)
treebbf78b2e8899c412ceede4a705d45368f61b51bf /docs/v3/series.js.html
parent89255fe326050e80ce5394a9c00e11e9be8b1005 (diff)
downloadasync-159a119fbb1a585c61f33b4b3b5036f5d332ebbb.tar.gz
Enhance examples for Collections methods. (#1726)
* Enhance examples for Collections methods. * Update collection example code, avoiding usage of IIFE on async/await examples * Convert examples on async.auto, async.series, and async.parallel to samples using Promises and async/await Co-authored-by: Roman Balayan <roman.balayan@paymaya.com>
Diffstat (limited to 'docs/v3/series.js.html')
-rw-r--r--docs/v3/series.js.html120
1 files changed, 110 insertions, 10 deletions
diff --git a/docs/v3/series.js.html b/docs/v3/series.js.html
index 02b62f3..bef4a61 100644
--- a/docs/v3/series.js.html
+++ b/docs/v3/series.js.html
@@ -113,35 +113,135 @@ import eachOfSeries from &apos;./eachOfSeries&apos;;
* with (err, result).
* @return {Promise} a promise, if no callback is passed
* @example
+ *
+ * //Using Callbacks
* async.series([
* function(callback) {
- * // do some stuff ...
- * callback(null, &apos;one&apos;);
+ * setTimeout(function() {
+ * // do some async task
+ * callback(null, &apos;one&apos;);
+ * }, 200);
* },
* function(callback) {
- * // do some more stuff ...
- * callback(null, &apos;two&apos;);
+ * setTimeout(function() {
+ * // then do another async task
+ * callback(null, &apos;two&apos;);
+ * }, 100);
* }
- * ],
- * // optional callback
- * function(err, results) {
- * // results is now equal to [&apos;one&apos;, &apos;two&apos;]
+ * ], function(err, results) {
+ * console.log(results);
+ * // results is equal to [&apos;one&apos;,&apos;two&apos;]
* });
*
+ * // an example using objects instead of arrays
* async.series({
* one: function(callback) {
* setTimeout(function() {
+ * // do some async task
* callback(null, 1);
* }, 200);
* },
- * two: function(callback){
+ * two: function(callback) {
* setTimeout(function() {
+ * // then do another async task
* callback(null, 2);
* }, 100);
* }
* }, function(err, results) {
- * // results is now equal to: {one: 1, two: 2}
+ * console.log(results);
+ * // results is equal to: { one: 1, two: 2 }
+ * });
+ *
+ * //Using Promises
+ * async.series([
+ * function(callback) {
+ * setTimeout(function() {
+ * callback(null, &apos;one&apos;);
+ * }, 200);
+ * },
+ * function(callback) {
+ * setTimeout(function() {
+ * callback(null, &apos;two&apos;);
+ * }, 100);
+ * }
+ * ]).then(results =&gt; {
+ * console.log(results);
+ * // results is equal to [&apos;one&apos;,&apos;two&apos;]
+ * }).catch(err =&gt; {
+ * console.log(err);
* });
+ *
+ * // an example using an object instead of an array
+ * async.series({
+ * one: function(callback) {
+ * setTimeout(function() {
+ * // do some async task
+ * callback(null, 1);
+ * }, 200);
+ * },
+ * two: function(callback) {
+ * setTimeout(function() {
+ * // then do another async task
+ * callback(null, 2);
+ * }, 100);
+ * }
+ * }).then(results =&gt; {
+ * console.log(results);
+ * // results is equal to: { one: 1, two: 2 }
+ * }).catch(err =&gt; {
+ * console.log(err);
+ * });
+ *
+ * //Using async/await
+ * async () =&gt; {
+ * try {
+ * let results = await async.series([
+ * function(callback) {
+ * setTimeout(function() {
+ * // do some async task
+ * callback(null, &apos;one&apos;);
+ * }, 200);
+ * },
+ * function(callback) {
+ * setTimeout(function() {
+ * // then do another async task
+ * callback(null, &apos;two&apos;);
+ * }, 100);
+ * }
+ * ]);
+ * console.log(results);
+ * // results is equal to [&apos;one&apos;,&apos;two&apos;]
+ * }
+ * catch (err) {
+ * console.log(err);
+ * }
+ * }
+ *
+ * // an example using an object instead of an array
+ * async () =&gt; {
+ * try {
+ * let results = await async.parallel({
+ * one: function(callback) {
+ * setTimeout(function() {
+ * // do some async task
+ * callback(null, 1);
+ * }, 200);
+ * },
+ * two: function(callback) {
+ * setTimeout(function() {
+ * // then do another async task
+ * callback(null, 2);
+ * }, 100);
+ * }
+ * });
+ * console.log(results);
+ * // results is equal to: { one: 1, two: 2 }
+ * }
+ * catch (err) {
+ * console.log(err);
+ * }
+ * }
+ *
*/
export default function series(tasks, callback) {
return _parallel(eachOfSeries, tasks, callback);