0

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");
});
JJJ
  • 32,902
  • 20
  • 89
  • 102
  • If it doesn't work as you intended it to work, then yes, you're making some mistake. – JJJ Nov 15 '15 at 15:08
  • Do you see any issue ? Reason I posted question here is , because it appears as if Parse is behaving erratically and code does not have issu. – Parse User Nov 15 '15 at 15:11
  • What does `createPromiseToUpdateStoreToCategoryMapObject` do? It does not modify `storeToCategoryMapList`, does it? – Bergi Nov 15 '15 at 17:37
  • What is `finalPromise`, btw? Looks like the [deferred antipattern](http://stackoverflow.com/q/23803743/1048572). – Bergi Nov 15 '15 at 17:38

0 Answers0