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, *args, &blk) ⇒ PeriodicTimer
constructor
Create a new timer that fires after a given number of seconds.
Methods included from Eventable
Constructor Details
#initialize(interval, *args, &blk) ⇒ PeriodicTimer
Create a new timer that fires after a given number of seconds
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'motion/reactor/periodic_timer.rb', line 10 def initialize(interval, *args, &blk) callback = args.first.respond_to?(:call) ? args.first : blk raise ArgumentError, "No callback or block supplied to periodic timer" unless callback callback.weak! if callback && BubbleWrap.use_weak_callbacks? = args.last.is_a?(Hash) ? args.last : {} if [:common_modes] NSLog "[DEPRECATED - Option :common_modes] a Run Loop Mode is no longer needed." end self.interval = interval leeway = interval queue = Dispatch::Queue.current @timer = Dispatch::Source.timer(leeway, interval, 0.0, queue) do callback.call trigger(:fired) end 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
31 32 33 34 |
# File 'motion/reactor/periodic_timer.rb', line 31 def cancel @timer.cancel! trigger(:cancelled) end |