Answer the question
In order to leave comments, you need to log in
Exact time on the server with an interval of 1 second?
I'm trying to get a "ticking" server with an exact or almost exact period of 1 second to get a relatively accurate time with an error of no more than 1 second. There is an example.com/timer
controller to which nodejs sends the current time with an interval of 1000ms. Then from the controller the time is output to the browser:
var request = require('request');
var requestLoop = setInterval(function() {
var time = Math.round(+new Date()/1000);
request({
url: "http://example.com/timer",
method: "POST",
data: {time: time},
followRedirect: false
});
}, 1000);
Answer the question
In order to leave comments, you need to log in
You have chosen the wrong technology (with an asynchronous "hammer" you are trying to synchronize the "nails").
Modern systems have learned to synchronize time quite well, so let the OS do it.
ps. Please note that the "deferred" call functions do not work accurately. The call to (setTime(fn, 100)) can happen after 100ms. or after 1200 (this depends on the workload of the main node.js loop).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question