Class: PeriodicTimer
Instance Method Summary collapse
Methods inherited from Timer
#cancel, #initialize, #reset, #running?, start
Constructor Details
This class inherits a constructor from Timer
Instance Method Details
#last_shot ⇒ Object
99 100 101 |
# File 'lib/infra/timer.rb', line 99 def last_shot @continue = false end |
#start(_interval = @interval, &block) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/infra/timer.rb', line 84 def start _interval=@interval, &block @continue = true changed and notify_observers(:ev_timer_start, id, Time.now.strftime("%M:%S")) _code = block || @code @_timer_thread_ = Thread.new(_interval, _code) do |interval, code| loop do sleep(interval) code.call if code changed and notify_observers(:ev_timer_fire, id, Time.now.strftime("%M:%S")) break unless @continue end changed and notify_observers(:ev_timer_stop, id, Time.now.strftime("%M:%S")) end self end |