Module: RSpec::Bash::FD

Defined in:
lib/rspec/bash/fd.rb

Class Method Summary collapse

Class Method Details

.noise?(error) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/rspec/bash/fd.rb', line 36

def self.noise?(error)
  error.to_s == "stream closed" || error.to_s == "closed stream"
end

.poll(fd, throttle: 25 / 1000, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rspec/bash/fd.rb', line 16

def self.poll(fd, throttle: 25 / 1000, &block)
  while readable?(fd) do
    begin
      yield fd
      sleep throttle if throttle > 0
    rescue IO::WaitReadable
      IO.select([ fd ])
      retry
    rescue IOError => e
      if noise? e
        break
      else
        throw e
      end
    rescue EOFError
      break
    end
  end
end

.readable?(fd) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rspec/bash/fd.rb', line 4

def self.readable?(fd)
  begin
    !fd.closed? && !fd.eof?
  rescue IOError => e
    if noise? e
      return false
    else
      throw e
    end
  end
end