title: Calling function in loop containing call to function containing a promise does not execute all the required times
body: <p>I have a for loop that calls a function in Javascript (getItemsForFolderID) for each item in that array(subfolders.data). 
  In this case there are 80 items in the array, but I can only see log statements for 6...
  getItemsForFolderID contains a promise that makes a call to a function that returns a promise and calls a REST API retrieving items (this works!)</p>
  
  <p>Anyone know why only 6 calls are made? I get 80 console entries for <code>console.log('Getting Items for: ' + subfolders.data[j].id)</code> but only six of either 
  <code>console.log('No items for folder: ' + folderID);</code> or <code>console.log('There were items');</code></p>
  
  <p>Here is the loop:</p>
  
  <pre><code>for (var j = 0; j &lt; subfolders.data.length; j++) {
      console.log('Getting Items for: ' + subfolders.data[j].id);
      getItemsForFolderID(subfolders.data[j].id);
  }
  </code></pre>
  
  <p>And the function we're calling:</p>
  
  <pre><code>function getItemsForFolderID(folderID) {
    var getItemsPromise = getItemsForFolderIDFromAPI(folderID);
    getItemsPromise.then(function(items) {
      if(items.data.length === 0) {
          console.log('No items for folder: ' + folderID);
      }
      else {
          console.log('There were items');
      }
    });
  }
  
  
  
  var RateLimiter = require('request-rate-limiter');
  
  var limiter = new RateLimiter({rate: 100, interval: 60, backoffCode: 429, backoffTime: 15, maxWaitingTime: 2600
  });
  
  function getItemsForFolderIDFromAPI(folderID) {
      return new Promise(function(resolve, reject) {
          limiter.request({
              url: url + '/' + folderID,
              method: 'get',
              headers: headers
          }).then(function (response) {
              resolve(JSON.parse(response.body));
          }).catch(function (err) {
              reject(error);
          });
      });
  }
  </code></pre>