summaryrefslogtreecommitdiff
path: root/docs/v3/auto.js.html
diff options
context:
space:
mode:
Diffstat (limited to 'docs/v3/auto.js.html')
-rw-r--r--docs/v3/auto.js.html88
1 files changed, 77 insertions, 11 deletions
diff --git a/docs/v3/auto.js.html b/docs/v3/auto.js.html
index e380d65..a1d65db 100644
--- a/docs/v3/auto.js.html
+++ b/docs/v3/auto.js.html
@@ -121,15 +121,40 @@ import { promiseCallback, PROMISE_SYMBOL } from './internal/promiseCallback
* @returns {Promise} a promise, if a callback is not passed
* @example
*
+ * //Using Callbacks
* async.auto({
- * // this function will just be passed a callback
- * readData: async.apply(fs.readFile, 'data.txt', 'utf-8'),
- * showData: ['readData', function(results, cb) {
- * // results.readData is the file's contents
- * // ...
+ * get_data: function(callback) {
+ * // async code to get some data
+ * callback(null, 'data', 'converted to array');
+ * },
+ * make_folder: function(callback) {
+ * // async code to create a directory to store a file in
+ * // this is run at the same time as getting the data
+ * callback(null, 'folder');
+ * },
+ * write_file: ['get_data', 'make_folder', function(results, callback) {
+ * // once there is some data and the directory exists,
+ * // write the data to a file in the directory
+ * callback(null, 'filename');
+ * }],
+ * email_link: ['write_file', function(results, callback) {
+ * // once the file is written let's email a link to it...
+ * callback(null, {'file':results.write_file, 'email':'user@example.com'});
* }]
- * }, callback);
+ * }, function(err, results) {
+ * if (err) {
+ * console.log('err = ', err);
+ * }
+ * console.log('results = ', results);
+ * // results = {
+ * // get_data: ['data', 'converted to array']
+ * // make_folder; 'folder',
+ * // write_file: 'filename'
+ * // email_link: { file: 'filename', email: 'user@example.com' }
+ * // }
+ * });
*
+ * //Using Promises
* async.auto({
* get_data: function(callback) {
* console.log('in get_data');
@@ -143,21 +168,62 @@ import { promiseCallback, PROMISE_SYMBOL } from './internal/promiseCallback
* callback(null, 'folder');
* },
* write_file: ['get_data', 'make_folder', function(results, callback) {
- * console.log('in write_file', JSON.stringify(results));
* // once there is some data and the directory exists,
* // write the data to a file in the directory
* callback(null, 'filename');
* }],
* email_link: ['write_file', function(results, callback) {
- * console.log('in email_link', JSON.stringify(results));
* // once the file is written let's email a link to it...
- * // results.write_file contains the filename returned by write_file.
* callback(null, {'file':results.write_file, 'email':'user@example.com'});
* }]
- * }, function(err, results) {
- * console.log('err = ', err);
+ * }).then(results => {
* console.log('results = ', results);
+ * // results = {
+ * // get_data: ['data', 'converted to array']
+ * // make_folder; 'folder',
+ * // write_file: 'filename'
+ * // email_link: { file: 'filename', email: 'user@example.com' }
+ * // }
+ * }).catch(err => {
+ * console.log('err = ', err);
* });
+ *
+ * //Using async/await
+ * async () => {
+ * try {
+ * let results = await async.auto({
+ * get_data: function(callback) {
+ * // async code to get some data
+ * callback(null, 'data', 'converted to array');
+ * },
+ * make_folder: function(callback) {
+ * // async code to create a directory to store a file in
+ * // this is run at the same time as getting the data
+ * callback(null, 'folder');
+ * },
+ * write_file: ['get_data', 'make_folder', function(results, callback) {
+ * // once there is some data and the directory exists,
+ * // write the data to a file in the directory
+ * callback(null, 'filename');
+ * }],
+ * email_link: ['write_file', function(results, callback) {
+ * // once the file is written let's email a link to it...
+ * callback(null, {'file':results.write_file, 'email':'user@example.com'});
+ * }]
+ * });
+ * console.log('results = ', results);
+ * // results = {
+ * // get_data: ['data', 'converted to array']
+ * // make_folder; 'folder',
+ * // write_file: 'filename'
+ * // email_link: { file: 'filename', email: 'user@example.com' }
+ * // }
+ * }
+ * catch (err) {
+ * console.log(err);
+ * }
+ * }
+ *
*/
export default function auto(tasks, concurrency, callback) {
if (typeof concurrency !== 'number') {