diff options
author | Caolan McMahon <caolan.mcmahon@gmail.com> | 2014-03-28 15:06:24 +0000 |
---|---|---|
committer | Caolan McMahon <caolan.mcmahon@gmail.com> | 2014-03-28 15:06:24 +0000 |
commit | 29f97dde28f0a2572628f894863c355af9130004 (patch) | |
tree | 3777afb0c766eeeff7c3a8a2a931d4ad0e85875d | |
parent | 1961d7da85cc9d13e97e3c56cdac98babc89da80 (diff) | |
parent | 908cf761de81fdfcc7d57f2b0a011229a40b1795 (diff) | |
download | async-29f97dde28f0a2572628f894863c355af9130004.tar.gz |
Merge pull request #398 from josher19/patch-1
Update async.auto example in README.md
-rw-r--r-- | README.md | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -1223,21 +1223,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); }); ``` @@ -1247,21 +1257,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'}); } ]); }); |