ES6 Generator Function vs Promises
<p>Please let me know if this is too vague of a question, but what are the advantages of using an ES6 generator function as opposed to promises? I don't see the advantage at the moment and was hoping someone could shed some light on it.</p>

<p>For example, when retrieving data in an asynchronous manner:</p>

<pre><code>/* Using promises */
fetch('api-endpoint')
   .then( resp =&gt; response.json() )
   .then( name =&gt; obj.name)
   .then( x =&gt; console.log('Name: ', name) )

//VS

/* As a generator function and assuming we have required node-fetch */
run(function *() {
   const url = 'api-endpoint';
   const resp = yield fetch(url);
   const obj = yield response.json();
   const name = yield obj.name;
   console.log("Name available here: ", name); 
}

function run(genFunc) {
   const iterator = genFunc();
   const iteration = iterator.next();
   const promise = iteration.value();
   promise.then( x =&gt; {
      const additionalIterator = iterator.next(x);
      const additionalPromise = iterator.value;
      additionalPromise.then( y =&gt; iterator.next(y));
   });
}
</code></pre>