Why is the native setInterval function adding 1 milliseconds after ~each new function call, which will be triggered by the interval?
This the log I get after I pinged the API for at least 20 times:
2017-09-10T12:42:56.568Z INFO: Pinging API
2017-09-10T12:42:58.569Z INFO: Pinging API
2017-09-10T12:43:00.569Z INFO: Pinging API
2017-09-10T12:43:02.570Z INFO: Pinging API
2017-09-10T12:43:04.570Z INFO: Pinging API
2017-09-10T12:43:06.571Z INFO: Pinging API
2017-09-10T12:43:08.571Z INFO: Pinging API
2017-09-10T12:43:10.571Z INFO: Pinging API
2017-09-10T12:43:12.572Z INFO: Pinging API
2017-09-10T12:43:14.572Z INFO: Pinging API
2017-09-10T12:43:16.572Z INFO: Pinging API
2017-09-10T12:43:18.573Z INFO: Pinging API
2017-09-10T12:43:20.574Z INFO: Pinging API
2017-09-10T12:43:22.574Z INFO: Pinging API
2017-09-10T12:43:24.575Z INFO: Pinging API
2017-09-10T12:43:26.576Z INFO: Pinging API
2017-09-10T12:43:28.576Z INFO: Pinging API
2017-09-10T12:43:30.576Z INFO: Pinging API
2017-09-10T12:43:32.577Z INFO: Pinging API
2017-09-10T12:43:34.577Z INFO: Pinging API
Currently my code is just doing the following inside the callback function:
setInterval(() => {
// this just logs the info
logger.info('Pinging API')
}, 2000)
I hope some one can explain me, when the interval is reset and why it isn't reliable on a millisecond basis (never mind the nanosecond basis)?
In modern browsers ...but this is about NodeJS, which isn't a browser.