summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolan McMahon <caolan.mcmahon@gmail.com>2014-03-28 15:06:24 +0000
committerCaolan McMahon <caolan.mcmahon@gmail.com>2014-03-28 15:06:24 +0000
commit29f97dde28f0a2572628f894863c355af9130004 (patch)
tree3777afb0c766eeeff7c3a8a2a931d4ad0e85875d
parent1961d7da85cc9d13e97e3c56cdac98babc89da80 (diff)
parent908cf761de81fdfcc7d57f2b0a011229a40b1795 (diff)
downloadasync-29f97dde28f0a2572628f894863c355af9130004.tar.gz
Merge pull request #398 from josher19/patch-1
Update async.auto example in README.md
-rw-r--r--README.md23
1 files changed, 21 insertions, 2 deletions
diff --git a/README.md b/README.md
index a41aebd..3249ed6 100644
--- a/README.md
+++ b/README.md
@@ -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'});
}
]);
});