0

https://www.npmjs.com/package/accurate-interval

This module will make sure that the interval is accurate forever. Why doesnt the native setInterval function work similiarly?

ThatBrianDude
  • 2,952
  • 3
  • 16
  • 42
  • But it corrects itself for the next callback though. AFAIK setInterval doesnt – ThatBrianDude Mar 28 '19 at 16:04
  • I really doubt, the mentioned package can be `accurate forever`, given how javascript is implemented (atleast in v8). Having said that, it could be `javascript` implementation dependent – 1565986223 Mar 28 '19 at 16:10
  • Of course there are ways to make it inaccurate on purpose but given you dont intentionally screw it up (or block the event loop accidentally), it will continue to be accurate. (Nothing runs FOREVER) – ThatBrianDude Mar 28 '19 at 16:13
  • https://stackoverflow.com/questions/196027/is-there-a-more-accurate-way-to-create-a-javascript-timer-than-settimeout – lifeisfoo Mar 28 '19 at 16:47
  • https://stackoverflow.com/questions/29971898/how-to-create-an-accurate-timer-in-javascript – lifeisfoo Mar 28 '19 at 16:47
  • @lifeisfoo I'd like to know WHY its not implemented accurately then. Is it too preserve legacy behaviour? – ThatBrianDude Mar 28 '19 at 17:05
  • It's by design. Please read more [about the js event loop](https://blog.risingstack.com/node-js-at-scale-understanding-node-js-event-loop/) to better understand why it works in this way. – lifeisfoo Mar 28 '19 at 17:41
  • I understand the event loop. You dont understand my question though. SetInterval has a clear functionality. It fails however to consistantly provide said functionality. There are ways (like in the mentioned module) to provide the functionatlity consistantly. My question is, why wasnt setInterval implemented properly in nodeJS when they had a chance too make it better than the implementation in the browser. Is it so that it stays consistent with the browser behaviour? – ThatBrianDude Mar 28 '19 at 17:51

0 Answers0