Reputation: 319
Interval isn't running once per millisecond. The final number only gets to 459 before stopping. Less if there is more than just a line on the interval. On here it doesn't even move through the first thousand. What I want is for it to run once per second to let me know how far an interval is done. So if testNum
is at 30, then I know that it's 97% of the way done (2970/3000)
.
let testNum = 3000
let testInt = setInterval(() => {
testNum--
}, 1)
let testTimeout = setTimeout(() => {
clearInterval(testInt)
console.log('Final Number: ' + testNum)
}, 3000)
Upvotes: 0
Views: 95
Reputation: 48827
From https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval#Parameters:
delay
The time, in milliseconds (thousandths of a second), the timer should delay in between executions of the specified function or code. If this parameter is less than 10, a value of 10 is used.
Have a look at Reasons for delays longer than specified as well.
Upvotes: 4