Meteor-Community-Packages / meteor-timesync

NTP-style time synchronization between server and client, and facilities to use server time reactively in Meteor applications.
https://packosphere.com/mizzao/timesync
MIT License
118 stars 36 forks source link

A somewhat smarter timeTick.depend() #19

Closed johanzhe closed 9 years ago

johanzhe commented 9 years ago

Hello Mizzao!

I'd like to propose a smarter way of triggering the SyncInternals.timeTick.changed(); dependency, so that it will trigger on the start of every second, this way the update on the client's screen (say if you're showing the current time) will look more synchronized. This could be implemented by replacing the Meteor.setInterval(function() {}) method with a Meteor.setTimeout(function() {}), and letting the enclosed function trigger the next setTimeout. I would implement it myself if I only knew a bit better about how git works...

Cheers!

mizzao commented 9 years ago

An improvement that can also consider #10 for more efficient synchronized updates of different time intervals.

mizzao commented 9 years ago

I don't think "the start of every second" is well defined since all clients are slightly off from each other. If use the default update of once per second, all reactive variables will update at the same time.

However, see the updates to TimeSync.serverTime if you'd like to change the rate at which the variable updates.