for of
syntax is useful to iterate over an iterator. But there is no way to access the return value for an iterator.
function *myWork() {
let x = 0
while (x < 10) yield (x++)/10
// the yielded number is work progress
return 'work result'
}
But for this kind of iterator, we can't use the for of
syntax to iterate over the iterator because it will ignore the result
for (const x of myWork()) console.log(x)
// "work result" is dropped
I have to iterate this kind of iterator by hand, it's not so good.