Share your repls and programming experiences

← Back to all posts
Better setInterval() for JavaScript
MrEconomical (2196)

This is a better version of the evil setInterval() function in JavaScript

Why is setInterval() evil?

  1. Does not wait for function to finish executing - this means that if you have an interval for let's say 200ms, and your function takes 5s to execute, it doesn't care that the function doesn't execute within 200ms and keeps calling it. This will eventually create a massive queue and cause many issues

  2. Does not care about errors - if there is an error in the function to be executed, it will keep executing and won't stop. This is a smaller issue but still pretty annoying

So I made a better version cool yey