Please see the
for(let value of Generators.input(btn2))
Why everytime run the cell calls the
Why run the cell multiple times, when the button clicked, the
console.log will be called multiple times?
btn2 not be a viewof.
I have fixed the code like this:
let gen = Generators.input(btn2)
await gen.next().value; //await is not neccessary. Just call next() is enough.
for(let value of gen)
I know that if I use I infinite async function, there’s no way to dispose the generator.
But I really don’t know why I must ignore the first generator value.
okok, I know why.
btn2.value is not undefined. Then
Generators.input will generator the value.
This will help viewof operator has the first initial value.
Now I understand this example https://observablehq.com/@mbostock/wait-until-button .
It is not pause the evaluation at the
button statement. But reference a not evaluated
button value, that makes that whole cell pause evaluation. Once button value is evaluated, this cell will run immediate whenever how many times the cell runs, it will never wait button click again.
If all you need is a button, then Mike’s example is actually a tiny bit over-engineered. A shorter form, along with some explanations, can be found here: