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