Class: EventMachine::AlignedPeriodic
- Inherits:
-
Object
- Object
- EventMachine::AlignedPeriodic
- Defined in:
- lib/eventmachine_alignedperiodic.rb
Constant Summary collapse
- VERSION =
'2.1.2'
Instance Attribute Summary collapse
-
#nextevent ⇒ Object
readonly
Returns the value of attribute nextevent.
Instance Method Summary collapse
-
#initialize(interval, p, offset = 0, logger = nil) ⇒ AlignedPeriodic
constructor
A new instance of AlignedPeriodic.
- #poke ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(interval, p, offset = 0, logger = nil) ⇒ AlignedPeriodic
Returns a new instance of AlignedPeriodic.
13 14 15 16 17 18 19 20 21 |
# File 'lib/eventmachine_alignedperiodic.rb', line 13 def initialize(interval, p, offset = 0, logger = nil) @interval = interval @offset = offset @p = p @logger = logger @partial = true @running = false @mutex = Mutex.new end |
Instance Attribute Details
#nextevent ⇒ Object (readonly)
Returns the value of attribute nextevent.
11 12 13 |
# File 'lib/eventmachine_alignedperiodic.rb', line 11 def nextevent @nextevent end |
Instance Method Details
#poke ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/eventmachine_alignedperiodic.rb', line 31 def poke @mutex.synchronize { # if we aren't running, we can't be poked unless @running raise "periodic schedulder not running; can't be poked" end EventMachine.cancel_timer(@timer) @p.call(true) @partial = true schedule_next_event } end |
#start ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/eventmachine_alignedperiodic.rb', line 23 def start @mutex.synchronize { EventMachine.add_shutdown_hook { @p.call(true) } @running = true schedule_first_event } end |
#stop ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/eventmachine_alignedperiodic.rb', line 44 def stop #Changed as per https://github.com/eventmachine/eventmachine/issues/418 if EM.reactor_running? EM.add_timer(0) { EventMachine.cancel_timer(@timer) if !@timer.nil? } end @running = false @timer = nil @p.call(true) end |