Class: Sysdo::EventSource::PolledChange

Inherits:
Sysdo::EventSource show all
Defined in:
lib/sysdo/event_source/polled_change.rb

Instance Attribute Summary

Attributes inherited from Sysdo::EventSource

#on_fire

Instance Method Summary collapse

Methods inherited from Sysdo::EventSource

#fire, #listen

Constructor Details

#initialize(poll_rate = 1, &value) ⇒ PolledChange

Returns a new instance of PolledChange.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sysdo/event_source/polled_change.rb', line 4

def initialize(poll_rate = 1, &value)        
  super() do |s|
    last = value.()

    loop do
      now = value.()
      if last != now
        s.fire(now)
      end
      last = now

      sleep poll_rate
    end
  end
end