title: How do you pass a value back to generator function when using for of loop
body: <p>I'm learning about generators and and iterators and I can't figure out, nor find any details on how to pass a value back to a generator object when iterating over the object using a <code>for of</code> loop. I'd like to pass the counter value back on each iteration. How is this possible?</p>
  
  <pre><code>function generate(time, id) {
    return new Promise((resolve, reject) =&gt; {
      setTimeout(() =&gt; {
        console.log(`ALERT: ${id}`)
        resolve(`${id} success.`)
      }, time)
    })
  }
  
  function* generator() {
    const testA = yield generate(3000, 'A')
    console.log(`Returned: ${testA}`)
    const testB = yield generate(500, 'B')
    console.log(`Returned: ${testB}`)
    const testC = yield generate(300, 'C')
    console.log(`Returned: ${testC}`)
  }
  
  async function test() {
    let counter = 1
    const genObj = generator()
    // await genObj.next(counter).value
    // counter += 1
    // await genObj.next(counter).value
    for (x of genObj) {
      console.log('From here.')
      const t = await x
      counter += 1
      console.log(t)
    }
  }
  
  test()
  </code></pre>