function* generator() {
const bar = yield 'foo' // bar may be *any* type
console.log(bar) // bar!
}
const iterator = generator()
// Start execution till we get first yield value
const foo = iterator.next()
console.log(foo.value) // foo
// Resume execution injecting bar
const nextThing = iterator.next('bar')
function* generator() {
try {
yield 'foo'
} catch (err) {
console.log(err.message) // bar!
}
}
var iterator = generator()
// Start execution till we get first yield value
var foo = iterator.next()
console.log(foo.value) // foo
// Resume execution throwing an exception 'bar'
var nextThing = iterator.throw(new Error('bar'))