I have written the code based on the Parse example provided in Parse.com to execute the promises in Series.
But, seems like sequential processing is not working fine.
The below code calls a cloud function namely 'sampleCloudFuction' multiple times but in sequential order through Series of Promises.
After executing the loop, app will make a call to another js function which will load the remaining items (excluding the processed items).
This is the Loop which make multiple calls to the cloud function:
var seriesPromise = new Parse.Promise.as();
$.each(items, function (i) {
..
..
count++;
if (count >= 25 || (i + 1) >= selectedItemsLength) {
.. ..
//Series Promise: The code to be executed in sequence being placed within the
//then() the existing promise
seriesPromise = seriesPromise.then(function () {
Parse.Cloud.run('sampleCloudFuction', itemsArray, function () {
console.log("success callback in JS");
var tempPromise = Parse.Promise.as();
return tempPromise;
}, function (error) {
alert("Error " + error.code + "::");
console.log("error callback in JS")
});
});
count = 0;
}
});
..
..
seriesPromise.then(function () {
//Fetch the approval state of the disabled button
alert("load remaining items");
});
The below function is to be called after executing the loop. But, this is being called well in before receiving the callbacks for all earlier requests.
seriesPromise.then(function () {
//Fetch the approval state of the disabled button
alert("load remaining items");
});