diff options
author | josher19 <josher19@gmail.com> | 2013-10-24 12:10:50 +0800 |
---|---|---|
committer | josher19 <josher19@gmail.com> | 2013-10-24 12:10:50 +0800 |
commit | 908cf761de81fdfcc7d57f2b0a011229a40b1795 (patch) | |
tree | f652647e5e29db66925aea918dd03011c0c3f3ed | |
parent | e345e1e29d41483d6064a8edb7645824bf5d47e2 (diff) | |
download | async-908cf761de81fdfcc7d57f2b0a011229a40b1795.tar.gz |
Update async.auto example in README.md
async.auto does not actually run (because callbacks not called) and does not illustrate main features of async.auto. Updated to use callback and console.log results.
-rw-r--r-- | README.md | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -1105,21 +1105,31 @@ __Example__ ```js async.auto({ get_data: function(callback){ + console.log('in get_data'); // async code to get some data + callback(null, 'data', 'converted to array'); }, make_folder: function(callback){ + console.log('in make_folder'); // 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(callback){ + write_file: ['get_data', 'make_folder', function(callback, results){ + 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); + callback(null, 'filename'); }], email_link: ['write_file', function(callback, results){ + 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); + console.log('results = ', results); }); ``` @@ -1129,21 +1139,30 @@ series functions would look like this: ```js async.parallel([ function(callback){ + console.log('in get_data'); // async code to get some data + callback(null, 'data', 'converted to array'); }, function(callback){ + console.log('in make_folder'); // 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'); } ], function(err, results){ async.series([ function(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 + results.push('filename'); + callback(null); }, function(callback){ + console.log('in email_link', JSON.stringify(results)); // once the file is written let's email a link to it... + callback(null, {'file':results.pop(), 'email':'user@example.com'}); } ]); }); |