Class: Harnex::Polling::PollingIO
- Inherits:
-
Object
- Object
- Harnex::Polling::PollingIO
- Defined in:
- lib/harnex/watcher/polling.rb
Constant Summary collapse
- EVENT_HEADER_SIZE =
16
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(dir_path) ⇒ PollingIO
constructor
A new instance of PollingIO.
- #readpartial(_maxlen) ⇒ Object
Constructor Details
#initialize(dir_path) ⇒ PollingIO
Returns a new instance of PollingIO.
18 19 20 21 22 |
# File 'lib/harnex/watcher/polling.rb', line 18 def initialize(dir_path) @dir_path = dir_path @snapshots = take_snapshot @closed = false end |
Instance Method Details
#close ⇒ Object
40 41 42 |
# File 'lib/harnex/watcher/polling.rb', line 40 def close @closed = true end |
#closed? ⇒ Boolean
44 45 46 |
# File 'lib/harnex/watcher/polling.rb', line 44 def closed? @closed end |
#readpartial(_maxlen) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/harnex/watcher/polling.rb', line 24 def readpartial(_maxlen) raise IOError, "closed stream" if @closed loop do sleep POLL_INTERVAL raise IOError, "closed stream" if @closed current = take_snapshot changed = detect_changes(@snapshots, current) @snapshots = current next if changed.empty? return encode_events(changed) end end |