Hey, a (hopefully) quick question to clarify. The following example is taken from https://observablehq.com/@mbostock/animation-loops
{
let i = 0;
while (true) {
yield Promises.tick(1000, ++i);
}
}
Imagine if I was instead performing a heavy computation in the while loop, say one that takes 50ms on average, and I want to yield every 100 ms. If I try to implement that naively in the while loop, would the result be one tick every 150 ms or every 100 ms? In case of the former, what is the right way to ensure a constant tick rate?
I’m asking because in this little notebook on randomly answering multiple choice tests, the amount of samples I take every loop grows exponentially:
const iterations = 10**(Math.log10(totalSamples)|0);
for(let j = 0; j < iterations; j++){
let correct = 0;
// answer totalQuestions questions at random
for (let i = 0; i < totalQuestions; i++){
if (randVals[--remainingVals] < correctChoice) correct++;
// generate new random values if we run out
if (remainingVals === 0) {
window.crypto.getRandomValues(randValsU8);
remainingVals = randVals.length;
}
}
rawData[correct]++;
totalSamples++;
}
The effect is nice, but for the last few loops I figure it might get a bit heavy, so I was curious what the best way to deal with that would be (I could use a worker but that is probably overkill).