Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 2129

Using promises to halt code execution.

$
0
0

I'm in a loop here,  for each iteration I'm calling _checkExistingDefaultTimes to check if a record exists.

 

 

The problem is, the code in loop is not ran until I'm outside the for loop....

 

 

Is there any way I can use Promise so that it forces the .then code (pushing oOpeningTimes) before the loop finishes?

 

 

   

    var oOpeningTimes = [];

    for (var i = 0; i < numberOfDays; i++) {

    this._checkExistingDefaultTimes(test.SiteInfo.SiteId,test.EffectiveDateFrom,     

     test.EffectiveDateTo)

           .then(function (bResult) {

 

 

               oOpeningTimes.push({

                   temporaryDate: oDate,

                   startTime1: oModelData[oWeekday].startTime1,

                   endTime1: oModelData[oWeekday].endTime1,              

               });

    });

 

 

     oStoreData.OpeningTimes = oOpeningTimes;

     oModel.setData(oStoreData);


Viewing all articles
Browse latest Browse all 2129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>