title: How to use async await inside Lodash _.times function?
body: <p>I would like to invoke an asynchronous function n times, invoking each time only after the previous one has resolved.</p>
  
  <p>This is the code that works: </p>
  
  <pre><code>async startGame() {
    for (let i = 0; i &lt; this.totalNumberOfSets; i++) {
    await this.startSet();
    }
  }
  </code></pre>
  
  <p>I would like to convert it to the Lodash function <code>_.times</code>.</p>
  
  <p>I tried using this answer: <a href="https://stackoverflow.com/questions/47065444/lodash-is-it-possible-to-use-map-with-async-functions">Lodash: is it possible to use map with async functions?</a></p>
  
  <p>this way:</p>
  
  <pre><code>async startGame() {
    await Promise.all(_.times(this.totalNumberOfSets, async () =&gt; {
      await this.startSet()
    }))
  };
  </code></pre>
  
  <p>but all the function invoked immediately four times without waiting to resolve.</p>
  
  <p>Also tried this:</p>
  
  <pre><code>  async startGame() {
     let resArray = [];
     await Promise.all(_.times(this.totalNumberOfSets, async () =&gt;{
       let res = await this.startSet()
       resArray.push(res);
      }
    ))
   };
  </code></pre>
  
  <p>but it didn't work as expected as well.</p>