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_path(path, preload = true) ⇒ Object



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

def add_path(path, preload=true)
  handler = FSSM::State.new(path)
  handler.refresh(path.to_pathname, true) if preload
  @handlers << handler
end

#runObject



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

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