title: JavaScript Promises - Waiting for resolution before moving on
body: <p>I have a requirement to do the following:</p>
  
  <ol>
  <li>Get a list of "lines" by calling an internal function (getLines()).</li>
  <li>Select the first line, perform an action</li>
  <li>After the previous action finishes, select the next line and do the same action</li>
  <li>Repeat for all lines (3-20 depending on user)</li>
  </ol>
  
  <p>I have the following code in place:</p>
  
  <pre><code>App.Lines = response.data;    
  for (var _i = 0; _i &lt; App.Lines.length; _i++) {
      var makeCallPromise = new Promise(
          function(resolve, reject) {
              Session.connection.ol.makeCall(App.Lines[_i], callBackFunction(response) {
                  //this can take up to 30 seconds to respond...
                  resolve(response.data);
              }, errorCallBackFunction(message) {
                  reject(message.error);
              }, bareJid);
          }
      )
      makeCallPromise.then(function(fulfilled) {
          console.log("PROMISE WORKED!!!!!", fulfilled);
      })
      .catch(function(error) {
          console.log("PROMISE FAILED!!!!!", error);
      });
  }
  </code></pre>
  
  <p>My hope was that the loop would wait to resolve the promise before it continued the loop, however, that's not the case.
  My question is whether or not it's possible to halt the loop until the resolution is complete.
  Note - I am using the bluebird JS library for promises.
  Thank you!</p>
  
  <p>Kind Regards,</p>
  
  <p>Gary</p>