Class: Harnex::Polling::PollingIO

Inherits:
Object
  • Object
show all
Defined in:
lib/harnex/watcher/polling.rb

Constant Summary collapse

EVENT_HEADER_SIZE =
16

Instance Method Summary collapse

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

#closeObject



40
41
42
# File 'lib/harnex/watcher/polling.rb', line 40

def close
  @closed = true
end

#closed?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/harnex/watcher/polling.rb', line 44

def closed?
  @closed
end

#readpartial(_maxlen) ⇒ Object

Raises:

  • (IOError)


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