[Pkg-javascript-commits] [node-async] 356/480: Added additional example for async.each

Jonas Smedegaard js at moszumanska.debian.org
Fri May 2 08:58:41 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository node-async.

commit f253cef6fcf8ff679b79639358b1650944603db2
Author: Justin Noel <github at calendee.com>
Date:   Mon Oct 28 13:46:42 2013 -0500

    Added additional example for async.each
    
    Signed-off-by: Justin Noel <github at calendee.com>
---
 README.md | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-async.git



More information about the Pkg-javascript-commits mailing list