Class: ZMachine::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/zmachine/timers.rb

Direct Known Subclasses

PeriodicTimer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval, callback = nil, &block) ⇒ Timer

Returns a new instance of Timer.



6
7
8
9
10
# File 'lib/zmachine/timers.rb', line 6

def initialize(interval, callback=nil, &block)
  @interval = interval
  @callback = callback || block
  schedule
end

Instance Attribute Details

#intervalObject

Returns the value of attribute interval.



4
5
6
# File 'lib/zmachine/timers.rb', line 4

def interval
  @interval
end

Instance Method Details

#cancelObject



20
21
22
# File 'lib/zmachine/timers.rb', line 20

def cancel
  @timer.cancel
end

#fireObject



16
17
18
# File 'lib/zmachine/timers.rb', line 16

def fire
  @callback.call
end

#scheduleObject



12
13
14
# File 'lib/zmachine/timers.rb', line 12

def schedule
  @timer = ZMachine.add_timer(@interval, method(:fire))
end