Class: BubbleWrap::Reactor::PeriodicTimer
- Inherits:
-
Object
- Object
- BubbleWrap::Reactor::PeriodicTimer
- Includes:
- Eventable
- Defined in:
- motion/reactor/periodic_timer.rb
Overview
Creates a repeating timer.
Instance Attribute Summary collapse
-
#interval ⇒ Object
Returns the value of attribute interval.
Instance Method Summary collapse
-
#cancel ⇒ Object
Cancel the timer.
-
#initialize(interval, callback = nil, &blk) ⇒ PeriodicTimer
constructor
Create a new timer that fires after a given number of seconds.
Methods included from Eventable
Constructor Details
#initialize(interval, callback = nil, &blk) ⇒ PeriodicTimer
Create a new timer that fires after a given number of seconds
10 11 12 13 14 15 16 17 |
# File 'motion/reactor/periodic_timer.rb', line 10 def initialize(interval, callback=nil, &blk) self.interval = interval fire = proc { (callback || blk).call trigger(:fired) } @timer = NSTimer.scheduledTimerWithTimeInterval(interval,target: fire, selector: 'call:', userInfo: nil, repeats: true) end |
Instance Attribute Details
#interval ⇒ Object
Returns the value of attribute interval.
7 8 9 |
# File 'motion/reactor/periodic_timer.rb', line 7 def interval @interval end |
Instance Method Details
#cancel ⇒ Object
Cancel the timer
20 21 22 23 |
# File 'motion/reactor/periodic_timer.rb', line 20 def cancel @timer.invalidate trigger(:cancelled) end |