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

Version Path
riemann-dash-0.2.4 lib/riemann/dash/public/clock.js
riemann-dash-0.2.3 lib/riemann/dash/public/clock.js
mindreframer-riemann-dash-0.2.3 lib/riemann/dash/public/clock.js
mindreframer-reslike-dash-0.2.2 lib/riemann/dash/public/clock.js
riemann-dash-0.2.1 lib/riemann/dash/public/clock.js
riemann-dash-0.2.0 lib/riemann/dash/public/clock.js
riemann-dash-0.1.1 lib/riemann/dash/public/clock.js
riemann-dash-0.1.0 lib/riemann/dash/public/clock.js