title: Generator in JavaScript not working due to being wrapped in an async request
body: <p>I want to return a generator for the cars being created. The issue is, I nest an API to receive some random colours for the cars upon which I cannot <code>yield</code> to since they're not declared as generator functions.</p>
  <p>I tried to create the reference using <code>let car</code> but because the request is <code>async</code>, it yields before the car is instanced. Perhaps I need to pass this as reference? Any ideas?</p>
  <pre><code>static async api()
  {
      return (await fetch('http://www.colr.org/json/colors/random/8')).json();
  }
  
  static* createCars(n)
  {
      for(let i = 1; i &lt;= n; i++) {
          Car.api().then(resp =&gt; {
              let car = (new self({
                  x: 0,
                  y: 250,
                  colour: &quot;#&quot; + resp.colors[3].hex,
                  windowsColour: &quot;#&quot; + resp.colors[2].hex,
                  number: i
              })).draw();
          });
          
          yield car;
      }
  }
  </code></pre>
  <blockquote>
  <p>Uncaught ReferenceError: car is not defined</p>
  </blockquote>