Class: NonblockingIOWrapper
- Inherits:
-
Object
- Object
- NonblockingIOWrapper
- Defined in:
- lib/bel_parser/parsers/nonblocking_io_wrapper.rb
Overview
Instance Method Summary collapse
-
#each {|buffer| ... } ⇒ Object
Yields each buffer read from the wrapped IO-like object to the provided block (e.g. { |block| … }).
-
#initialize(io, read_length = (128 * 1024)) ⇒ NonblockingIOWrapper
constructor
Initialize this wrapper around the
io
object and read at mostread_length
bytes in a non-blocking manner.
Constructor Details
#initialize(io, read_length = (128 * 1024)) ⇒ NonblockingIOWrapper
Initialize this wrapper around the io
object and read at most read_length
bytes in a non-blocking manner.
10 11 12 13 14 |
# File 'lib/bel_parser/parsers/nonblocking_io_wrapper.rb', line 10 def initialize(io, read_length = (128 * 1024)) @io = io @read_length = read_length @read_method = nonblocking_read(@io) end |
Instance Method Details
#each {|buffer| ... } ⇒ Object
Yields each buffer read from the wrapped IO-like object to the provided block (e.g. { |block| … }). The read length is set on #initialize.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bel_parser/parsers/nonblocking_io_wrapper.rb', line 21 def each while (buffer = @read_method.call(@read_length)) yield buffer end rescue IO::WaitReadable IO.select([@io]) retry # rubocop:disable HandleExceptions rescue EOFError # end of stream; parsing complete end |