summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md35
1 files changed, 34 insertions, 1 deletions
diff --git a/README.md b/README.md
index aff0040..ae34987 100644
--- a/README.md
+++ b/README.md
@@ -168,7 +168,40 @@ __Arguments__
* callback(err) - A callback which is called after all the iterator functions
have finished, or an error has occurred.
-__Example__
+__Examples__
+
+```js
+// assuming openFiles is an array of file names and saveFile is a function
+// to save the modified contents of that file:
+
+async.each(openFiles, function( file, callback) {
+
+ // Perform operation on file here.
+ console.log('Processing file ' + file);
+ callback();
+
+ if( file.length > 32 ) {
+ console.log('This file name is too long');
+ callback('File name too long');
+
+ return;
+ } else {
+ console.log('File saved');
+ callback();
+ }
+}, function(err){
+ // if any of the saves produced an error, err would equal that error
+ if( err ) {
+ // One of the iterations produced an error.
+ // All processing will now stop.
+ console.log('A file failed to process');
+ } else {
+ console.log('All files have been processed successfully');
+ }
+});
+```
+
+---------------------------------------
```js
// assuming openFiles is an array of file names and saveFile is a function