title: async await in forEach
body: <p>I have the following function that works as expected:</p>
  
  <pre><code>  createObjectFrom(record) {
      let obj = {};
  
      this.opts.transformers.forEach((transformer, index) =&gt; {
        const headerIndex = findIndex(this.headers, (header) =&gt; {
          return header === transformer.column;
        });
  
        const value = transformer.formatter(record[headerIndex]);
  
        obj[transformer.field] = value;
      });
  
      return obj;
    }
  </code></pre>
  
  <p>I want to refactor it to use async await and call an async function in the body of the forEach like this:</p>
  
  <pre><code>  createObjectFrom(record) {
      let obj = {};
  
      this.opts.transformers.forEach(async (transformer, index) =&gt; {
        const headerIndex = findIndex(this.headers, (header) =&gt; {
          return header === transformer.column;
        });
  
        const result = await this.knex('managers').select('name')
  
        console.log(result);
  
        const value = transformer.formatter(record[headerIndex]);
  
        obj[transformer.field] = value;
      });
  
      return obj;
    }
  </code></pre>
  
  <p>This will obviously break the function as the forEach is now executing asynchronously and the function will just execute and leave.</p>
  
  <p>Is there a way I can use async await for the forEach to execute in a synchronous manner.  Could I refactor to generators?</p>