how to break async.js each loop?
callback, javascript, loops, node.js
Solution
`async.until` repeatedly calls function until the test returns true. So test must return true so that you exit the loop. This is opposite of `async.whilst` which runs repeatedly while test evaluates to be true.
`async.each` calls the functions in parallel so what it returns does not matter. It is not a loop which you can break, but an iterator looping over the array. Your condition to stop using `async.each` should be in test for `async.until` and you should iterate over the rules yourself.
Problem
Hi i am using async module of node.js for implementing a for loop asynchronously. My question is: how to break the loop execution and get out of the loop? I tried giving `return` , `return false` but no luck. Here is the sample code: ``` async.until( function() { return goal; }, function(callback) { async.each(_rules, function(rule,callback) { var outcome = true; .... some code .... if(changes){ console.log("hi"); return false;// HERE I NEED TO BREAK } else callback(); }, function(err){ } ); if (!changes || session.process) goal = true; callback(); }, function(err){ callback(session); } ); ```