Sha256: e9cc812ca69c4beb8c19a539cffed0360b1e23a3647f8c221ad839a154293681
Contents?: true
Size: 901 Bytes
Versions: 8
Compression:
Stored size: 901 Bytes
Contents
// Global clock var clock = (function() { var clock = new Date(); var offset = 0; var callback_i = 0; var callbacks = {}; var advance = function(t) { if (clock < t) { // New local offset offset = t - (new Date()); //console.log("new offset is", offset); clock = t; } //console.log("Clock is", clock); } var register = function(f) { callback_i = callback_i + 1; callbacks[callback_i] = f; return callback_i; } var unregister = function(i) { callbacks.delete(i); } // Automatically advance clock. setInterval(function() { offset = offset * 0.99; advance(new Date(new Date().valueOf() + offset)); $.each(callbacks, function(k, f) { f(clock); }); }, 1000); return { 'clock': clock, 'offset': offset, 'advance': advance, 'register': register, 'unregister': unregister } })();
Version data entries
8 entries across 8 versions & 3 rubygems