I'm looking for an efficient (not continuous polling) way to execute a function whenever the real time clock turns over to a new minute. My current code uses setInterval to call the function every 60 seconds -- but in practice there is some lagging and the function is getting called at about 60.2 seconds on average. This is leading to a cumulative error that builds up in a process monitoring system I'm developing.
Does anyone out there have a clever bit of code that calls a function at regular intervals triggered by the real time clock?
Edit: I was alerted to a method to compensate for the error by checking the time each time the function was called and compensating the setInterval value for the next call. This gets me closer -- but what I'm really after is a method to call a function right at the start of a new minute according to the real time clock...