title: node.js for loop parallel array processing with only one callback
body: <p>i want to make a for loop with a pattern-array and one object to check if the object is matched by one pattern. The patterns-array should processed parallel and if one of the patterns matches the object the onMatch()-callback-function should be called and cancel the other operations else the onNoMatch()-function should be called.</p>
  
  <p>At the Moment it looks like this. I dont know where to put the onNoMatch()-function and sometimes there are multiple callbacks:</p>
  
  <pre><code>module.exports = function matchingPattern(patterns, object, onMatch, onNoMatch) {
      for (key in patterns) {
          if(patterns[key].param1 != object.param1) continue;
          else if(patterns[key].param2 != object.param2) continue;
          else if(patterns[key].param3 != object.param3) continue;
          else {
              onMatch(patterns[key].id);
          }
      }
  }
  </code></pre>
  
  <p>//EDIT working solution</p>
  
  <pre><code>var arr = [1,2,3,4,5]
  var async = require('async');
  
  function matchPattern(pat, object, cb){
      console.log(pat +' % '+ object);
      if(pat % object == 0) cb(pat); 
      else cb();
  }
  
  function matchingPattern(patterns, object, onMatch, onNoMatch) {
      async.each(patterns, function(pat, callback){
          matchPattern(pat, object, function(match){
              return callback(match);
          });
      }, function (res){
          if(res) return onMatch(res);
          return onNoMatch()
      });
  }
  
  matchingPattern(arr, {2=2matches, 6=no matches}, function onMath(a){
      console.log('onMatch('+a+')');
  }, function onNoMatch(){
      console.log('onNoMatch()');
  });
  </code></pre>