Class: Warchat::Timer
- Inherits:
-
Object
- Object
- Warchat::Timer
- Defined in:
- lib/warchat/timer.rb
Instance Method Summary collapse
-
#initialize(interval, &handler) ⇒ Timer
constructor
A new instance of Timer.
- #stop ⇒ Object
Constructor Details
#initialize(interval, &handler) ⇒ Timer
Returns a new instance of Timer.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/warchat/timer.rb', line 6 def initialize(interval, &handler) raise ArgumentError, "Illegal interval" if interval < 0 @interval = interval extend MonitorMixin @run = true @th = Thread.new do while run? if do_sleep begin handler.call rescue Exception => e Warchat.debug e. Warchat.debug e.backtrace end end end end @th['name'] = 'Timer' end |
Instance Method Details
#stop ⇒ Object
27 28 29 30 31 32 |
# File 'lib/warchat/timer.rb', line 27 def stop synchronize do @run = false end sleeping? and @th.kill or @th.join end |