Class: Sysdo::EventSource::PolledEqualChange

Inherits:
Sysdo::EventSource show all
Defined in:
lib/sysdo/event_source/polled_equal_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(equal, poll_rate = 1, &value) ⇒ PolledEqualChange

Returns a new instance of PolledEqualChange.



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

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

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

      sleep poll_rate
    end
  end
end