Sha256: 5bb459e46546c8dc2a59a7a4f882de1b2e1a7859afe63f97ddcd458092b0448a
Contents?: true
Size: 887 Bytes
Versions: 33
Compression:
Stored size: 887 Bytes
Contents
module Einhorn::Event class Timer attr_reader :time def initialize(time, start=nil, &blk) @time = time @start = start || Time.now @blk = blk end # TODO: abstract into some interface def self.open(*args, &blk) instance = self.new(*args, &blk) instance.register! instance end def expires_at @start + @time end def ring! now = Time.now Einhorn.log_debug("Ringing timer that was scheduled #{now - @start}s ago and expired #{now - expires_at}s ago") deregister! @blk.call end def register! Einhorn.log_debug("Scheduling a new #{self.time}s timer") Einhorn::Event.register_timer(self) end def deregister! Einhorn.log_debug("Nuking timer that expired #{Time.now - self.expires_at}s ago") Einhorn::Event.deregister_timer(self) end end end
Version data entries
33 entries across 33 versions & 1 rubygems