Implement a resumable interval function
resumeInterval is a utility function using which we can create intervals that can be paused, restarted and stopped.
It takes the same signature as window.setInterval()
and returns an object with the following methods:
start
: executes the callback immediately and every interval seconds.paused
: pauses the running interval. Calling start again should restart the interval again.stop
: permanently stops the interval. Once stopped, intervals can be started or paused again.
1. Basic implementation
Further Reading
I strongly encourage you to explore and tackle additional questions in my Closure Questions for Frontend Interviews blog series.
By doing so, you can enhance your understanding and proficiency with closures, preparing you to excel in your upcoming frontend interviews.
Wishing you best. Happy Interviewing 🫡.