Perform nonblocking reads on a streaming IO instance.
@api private
@!attribute [r] #max_delay
@return [Float] The maximum time to wait while polling the IO device
@!attribute [r] #min_delay
@return [Float] The minimum time to wait while polling the IO device
!@attribute [r] string
@return [String] The output collected from the IO device
# File lib/r10k/util/subprocess/runner/pump.rb, line 20 def initialize(io) @io = io @thread = nil @string = '' @run = true @min_delay = 0.05 @max_delay = 1.0 end
# File lib/r10k/util/subprocess/runner/pump.rb, line 33 def halt! @run = false @thread.join end
# File lib/r10k/util/subprocess/runner/pump.rb, line 29 def start @thread = Thread.new { pump } end
Block until the pumping thread reaches EOF on the IO object.
# File lib/r10k/util/subprocess/runner/pump.rb, line 39 def wait @thread.join end
# File lib/r10k/util/subprocess/runner/pump.rb, line 45 def pump backoff = @min_delay while @run begin @string << @io.read_nonblock(4096) backoff /= 2 if backoff > @min_delay rescue Errno::EWOULDBLOCK, Errno::EAGAIN backoff *= 2 if backoff < @max_delay IO.select([@io], [], [], backoff) rescue EOFError @run = false end end end