title: When using redux-saga, why yield statement is the value of the execution rather than undefined?
body: <p>Let's say we have the following generator function:</p>
  
  <pre>
  <code>function* testGenerator() {</code>
  
  <code>  const result = yield Promise.resolve('foobar')<del>.then(res => res);</del></code>
  
  <code>  console.log(result);</code>
  
  <code>}</code>
  </pre>
  
  <p>If I run this generator with the following line, it logs <code>undefined</code></p>
  
  <pre><code>const test = testGenerator();
  test.next();
  test.next();
  </code></pre>
  
  <p>But in saga, such lines will log <code>foobar</code>. I'm just curious what's the mechanism behind this (assigning the result of yield to a variable)</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>TL;DR: </p>
  
  <p><a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/function*" rel="nofollow noreferrer">MDN function* reference</a></p>
  
  <blockquote>
    <p>Calling the next() method with an argument will resume the generator
    function execution, replacing the yield statement where execution was
    paused with the argument from next()</p>
  </blockquote>
  
  <p>Basically, to get it to log "foobar", just pass the value of the first yield to the second next so when it resumes, yield statement is replaced by the value:</p>
  
  <pre><code>function* testGenerator() {
    const result = yield Promise.resolve('foobar');
    console.log(result);
  }
  
  const test = testGenerator();
  test.next().value.then(r =&gt; test.next(r))
  </code></pre>