Sha256: dd5417b129131bb159c1d3d3b8332a2ca7f938b29b4bf52ec9de9fbb60b17ec6
Contents?: true
Size: 1003 Bytes
Versions: 3
Compression:
Stored size: 1003 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 advanced to", t / 1000); } } var subscribe = function(f) { callback_i = callback_i + 1; callbacks[callback_i] = f; return callback_i; } var unsubscribe = function(i) { delete callbacks[i]; } // Automatically advance clock. setInterval(function() { t1 = new Date(); offset = offset * 0.99; advance(new Date(t1.valueOf() + offset)); $.each(callbacks, function(k, f) { f(clock); }); t2 = new Date(); subs.load1(t1, t2); subs.load5(t1, t2); }, 1000); return { 'clock': clock, 'offset': offset, 'advance': advance, 'subscribe': subscribe, 'unsubscribe': unsubscribe } })();
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
riemann-dash-0.2.7 | lib/riemann/dash/public/clock.js |
riemann-dash-0.2.6 | lib/riemann/dash/public/clock.js |
riemann-dash-0.2.5 | lib/riemann/dash/public/clock.js |