title: How to handle each response in successCallBack of promises in case of dynamic passage of promises to .when()
body: <p>Here are the cloud functions namely 'batchReq1' and batchPromises.</p>
  
  <p>In any case, if I know the exact number of promises pushed (Consider the size of results to be '2' in function batchPromises(results)) and executed through when(), I can handle the success response by passing that number of result parameters (In the below example request1, request2) in successCallBack of .then(). </p>
  
  <p>If I have to process the number of promises pushed to .when() dynamically, then, how can we handle this in SuccessCallBack? Unlike earlier scenario, we can't expect fixed number of results in the then method (batchPromises(results).then(function (result1, result2) {....)</p>
  
  <p><strong>batchReq1</strong></p>
  
  <pre><code>Parse.Cloud.define("batchReq1", function (request, response) {
  
      var results = request.params.imageArray;
  
  
      batchPromises(results).then(function (result1, result2) {
  
              console.log("Final Result:: Inside Success");
  
              console.log("Final Result:: Inside Success result 1::::"+result1);
              console.log("Final Result:: Inside Success result 2::::"+result2);
  
              response.success();
  
          }
  
  
  
  //    batchPromises(results).then(function (arraySuccess) {
  //
  //        console.log("Final Result:: Inside Success");
  //        console.log("Final Result:: Inside Success:: Length:: "+arraySuccess.length);
  //        //Fetch all responses from promises and display
  //        var _ = require('underscore.js');
  //        _.each(arraySuccess, function (result) {
  //
  //            console.log("Final Result:: " + result)
  //
  //        });
  //
  //
  //        response.success();
  //
  //    }
  
  
  
          , function (error) {
          console.log("Final Result:: Inside Error");
          response.error(error);
  
      });
  
  });
  </code></pre>
  
  <p><strong>batchPromises</strong></p>
  
  <pre><code>function batchPromises(results) {
  
      var promise = Parse.Promise.as();
      var promises = [];
  
  
      var increment = 0;
      var isFromParallelExecution = false;
  
  
      var _ = require('underscore.js');
      _.each(results, function (result) {
  
  
  
  
          var tempPromise = Parse.Promise.as("Promise Resolved ");
          promises.push(tempPromise);
          }
  
  
              promise = promise.then(function () {
  
                 return Parse.Promise.when(promises);
  
              });
  
          }
          increment++;
      });
  
      return promise;
  }
  </code></pre>