When iterating over a generator using a for of loop, is there a way to, pass a value back to the generator?
In the following code, when I call iterable.next('some value') manually, I can pass a value back, but the for of loop seems to call the .next() method without any value.
I hope I've explain this in an understandable way.
const test = function* generator() {
const list = [1, 2, 3, 4]
for (const x of list) {
const data = yield x
console.log(data)
}
}
const iterable = test()
console.log(iterable.next())
console.log(iterable.next('test2'))
console.log('FOR OF LOOP')
for (const y of iterable) {
console.log(y)
}