title: batch mode with promise in javascript
body: <p>I need to process a lot of data. For each entry of the data, we need to submit query to mysql. my current solution is like following:</p>
  
  <pre><code>    var Q = require('q');
      function process(entry){
          ...
          var defered=Q.defer();
          connection.query(sql,defered.makeNodeResolver());
          return defered.promise;
      }
      function ProcessAll(results ) {
          var waitfor=[];
          for( var i=0;i&lt; results.length;i++){
              waitfor.push( process(results[i]));
          }
          Q.all(waitfor).then(function(results) {
              notifySuc(results);
          },function(results){
              notifyFail(results);
          });
      }
  </code></pre>
  
  <p>However when the number of the data is huge, it will crash due to out of memory:</p>
  
  <pre><code>FATAL ERROR: Committing semi space failed. Allocation failed - process out of memory
  
   1: node::Abort() [node]
   2: 0x109624c [node]
   3: v8::Utils::ReportApiFailure(char const*, char const*) [node]
   4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
   5: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
   6: v8::internal::Heap::CollectGarbage(v8::internal::GarbageCollector, char const*, char const*, v8::GCCallbackFlags) [node]
  </code></pre>
  
  <p>How can I break it with smaller batches? For example, we can process 1000 entries each time. After they are all one we resume the rest. How to do so with the callback functions?</p>
  
  <p>In addition, can we make multiple entries get processed in parallel?</p>