I’ve seen this technique in multiple notebooks:
while (true) {
doSomeSVG(g);
yield svg.node();
}
There is clearly a “runner” of the generator calling “next” so maybe it is using a settimeout, or rAF?
I am converting my notebook to a JS version to have both worlds (the Good and the Bad & Ugly!)
My question is: I think tight yield loops are blocking operations in JS. How should I convert to a “runner” that uses async on the next calls? Or maybe I can just use the Observable std lib?
Example: running this on a blank page in the browser works, although too fast to see:
function* nextIntegerGenerator(index) {
while (true) {
yield index++
}
}
nextInteger = nextIntegerGenerator(0)
for (let i = 0; i < 10; i++) {
document.body.innerText = nextInteger.next().value
}
But this hangs the browser:
while (true) {
document.body.innerText = nextInteger.next().value
}