Class: FSSM::Backends::Polling

Inherits:
Object
  • Object
show all
Defined in:
lib/fssm/backends/polling.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Polling

Returns a new instance of Polling.



3
4
5
6
# File 'lib/fssm/backends/polling.rb', line 3

def initialize(options={})
  @handlers = []
  @latency  = options[:latency] || 1.5
end

Instance Method Details

#add_handler(handler, preload = true) ⇒ Object



8
9
10
11
# File 'lib/fssm/backends/polling.rb', line 8

def add_handler(handler, preload=true)
  handler.refresh(nil, true) if preload
  @handlers << handler
end

#runObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fssm/backends/polling.rb', line 13

def run
  begin
    loop do
      start = Time.now.to_f
      @handlers.each { |handler| handler.refresh }
      nap_time = @latency - (Time.now.to_f - start)
      sleep nap_time if nap_time > 0
    end
  rescue Interrupt
  end
end