In the below function createPromiseToUpdateStoreToCategoryMapObject
is a function which returns a promise.
If I comment listOfPromises.push( createPromiseToUpdateStoreToCategoryMapObject( storeToCategoryMapList[temp] ) );
loop runs 3 times, as find()
returns 3 items.
However, if I uncomment it, loop runs only once. Am I making any mistake here?
createPromiseToUpdateStoreToCategoryMapObject
updates/saves object available in storeToCategoryMapList[temp]
.
storeToCategoryMapQuery.find().then(function( storeToCategoryMapList) {
console.log("updateAllStoresOfRetailerCategoryMapObject");
var promiseToSaveStoreToCategoryMap = Parse.Promise.as();
console.log("Total Stores = " + storeToCategoryMapList.length);
var listOfPromises = [];
for ( var temp=0; temp<storeToCategoryMapList.length;temp++) {
console.log(" temp =" + temp)
listOfPromises.push( createPromiseToUpdateStoreToCategoryMapObject( storeToCategoryMapList[temp] ) );
}
return Parse.Promise.when(listOfPromises);
}).then(function(){
console.log("Successs in updateAllStoresOfRetailerCategoryMapObject ");
finalPromise.resolve();
},function(error){
console.log("updateAllStoresOfRetailerCategoryMapObject error======" + JSON.stringify(error));
finalPromise.resolve("problem");
});