Which fix removes the bug?
let timer;
function poll() {
timer = setInterval(fetchNow, 1000);
}
poll();
poll();
- Call
clearInterval(timer)before setting - Call
clearTimeout(timer)before setting - Change
setIntervaltosetTimeouthere - Declare
timerinside thepollfunction
The second call orphans the first interval, which keeps firing forever; clear it first.
Play Problem Solving ▸