title: SAPUI5 Using promises to wait for code execution
body: <p>I'm in a loop here and for each iteration I'm calling <code>_checkExistingDefaultTimes</code> to check if a record exists.</p>
  
  <p>The problem is, the code in the loop is not executed until I'm outside the for loop.</p>
  
  <p>Is there any way I can use a Promise so that it forces the <code>.then</code> code (pushing oOpeningTimes) before the loop finishes?</p>
  
  <pre><code>var oOpeningTimes = [];
  for (var i = 0; i &lt; 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);
  </code></pre>