Module: IOMultiplex::Mixins::Timer
- Included in:
- IOMultiplex::Multiplexer
- Defined in:
- lib/iomultiplex/mixins/timer.rb
Overview
Timer handling methods Depends on Mixins::State TODO: We should use monotonic clock here!
Instance Method Summary collapse
Instance Method Details
#add_timer(timer, at) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/iomultiplex/mixins/timer.rb', line 23 def add_timer(timer, at) raise ArgumentError, 'Timer must response to "timer"' \ unless timer.respond_to? :timer state = get_state(timer) exists = state & State::STATE_TIMER != 0 @timers.delete [@timers_time[timer], timer] if exists entry = [at, timer] @timers.add entry @timers_time[timer] = at add_state timer, State::STATE_TIMER unless exists nil end |
#remove_timer(timer) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/iomultiplex/mixins/timer.rb', line 39 def remove_timer(timer) state = must_get_state(timer) return unless state & State::STATE_TIMER != 0 entry = [@timers_time[timer], timer] remove_timer_state entry nil end |