Avraham
Avraham

Reputation: 63

The most accurate way to do something at a constant rate in JS

I need to run a function every fixed time with maximum precision. For example, every 30 milliseconds a function will run. I tried this code:

this.interval = setInterval(() => {
            this.foo();
        }, 30);

But when I add the number of actions called in a certain time period with another time period of the same length, I get a different number!

Is there a way to solve this? That the accuracy in running the functions will be the same?

Upvotes: 0

Views: 44

Answers (0)

Related Questions