Sha256: 80e91f7575df0e5f549686eddbbc0c6179c61c3bdd54116ad9853d373f0800d8
Contents?: true
Size: 1.16 KB
Versions: 39
Compression:
Stored size: 1.16 KB
Contents
# encoding: utf-8 module OneApm module Support class EventLoop class Timer attr_reader :next_fire_time, :event, :interval, :last_fired_at def initialize(interval, event, repeat=false) @interval = interval @event = event @repeat = repeat @started_at = Time.now @last_fired_at = nil reschedule end def reschedule @next_fire_time = calculate_next_fire_time end def advance(amount) @next_fire_time -= amount end def last_interval_start @last_fired_at || @started_at end def calculate_next_fire_time now = Time.now return now if @interval == 0 fire_time = @last_fired_at || now while fire_time <= now fire_time += @interval end fire_time end def set_fired_time @last_fired_at = Time.now end def due?(now=Time.now) now >= @next_fire_time end def finished? !@repeat && @last_fired_at end end end end end
Version data entries
39 entries across 39 versions & 1 rubygems