Class: FSSM::Backends::Polling
- Inherits:
-
Object
- Object
- FSSM::Backends::Polling
- Defined in:
- lib/fssm/backends/polling.rb
Instance Method Summary collapse
- #add_handler(handler, preload = true) ⇒ Object
-
#initialize(options = {}) ⇒ Polling
constructor
A new instance of Polling.
- #run ⇒ Object
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(={}) @handlers = [] @latency = [: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 |
#run ⇒ Object
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 |