title: Dynamically creation of promises and running sequentially
body: <p>I'm running into the following problem.</p>
  
  <p>I have the following promise (simplified):</p>
  
  <pre><code>module.exports.checkVotes = (groupId) =&gt;{
      return new Promise((resolve, reject)=&gt;{
       // some db stuff onoing
       ...
       .then((votes)=&gt;{return resolve(votes}})
       .catch((err)=&gt;{return reject(err}})
      })
  }
  </code></pre>
  
  <p>At some point I'm looping through an object. For each entry i have to call promise above. But before the 2. Promise starts, the first one have to be finished...and so on.
  I tried this, but as soon as I call the promise it gets executed.</p>
  
  <pre><code> .then(()=&gt;{
        for (let i=0;i&lt;groups.length;i++){
             // for each group I want to call the promise later
             //but it executes as soon as I push it.
             tasklist.push(this.checkVotes(groups[i])) 
         }
  
         return tasklist.reduce((promiseChain, currentTask) =&gt; {
             return promiseChain.then(chainResults =&gt;
                 currentTask.then(currentResult =&gt;
                      [ ...chainResults, currentResult ]
                  )
             );
          }, Promise.resolve([])).then(arrayOfResults =&gt; {
                  console.log(arrayOfResults)
              }).catch((err) =&gt;{console.log(err)});
           })
    })
  </code></pre>
  
  <p>I can not run this with Promise.all() because for some database things, I need this to run sequentially. Moreover I can not hardcode this because the number of groups is variable.</p>
  
  <p>How can I solve this?</p>
  
  <p>Thanks for helping</p>