Class: Qs::IOPipe
- Inherits:
-
Object
- Object
- Qs::IOPipe
- Defined in:
- lib/qs/io_pipe.rb
Constant Summary collapse
- NULL =
File.open('/dev/null', 'w')
- NUMBER_OF_BYTES =
1
Instance Attribute Summary collapse
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Instance Method Summary collapse
-
#initialize ⇒ IOPipe
constructor
A new instance of IOPipe.
- #read ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
- #wait(timeout = nil) ⇒ Object
- #write(value) ⇒ Object
Constructor Details
Instance Attribute Details
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
8 9 10 |
# File 'lib/qs/io_pipe.rb', line 8 def reader @reader end |
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
8 9 10 |
# File 'lib/qs/io_pipe.rb', line 8 def writer @writer end |
Instance Method Details
#read ⇒ Object
26 27 28 |
# File 'lib/qs/io_pipe.rb', line 26 def read @reader.read_nonblock(NUMBER_OF_BYTES) end |
#setup ⇒ Object
15 16 17 |
# File 'lib/qs/io_pipe.rb', line 15 def setup @reader, @writer = ::IO.pipe end |
#teardown ⇒ Object
19 20 21 22 23 24 |
# File 'lib/qs/io_pipe.rb', line 19 def teardown @reader.close unless @reader === NULL @writer.close unless @writer === NULL @reader = NULL @writer = NULL end |
#wait(timeout = nil) ⇒ Object
34 35 36 |
# File 'lib/qs/io_pipe.rb', line 34 def wait(timeout = nil) !!::IO.select([@reader], nil, nil, timeout) end |
#write(value) ⇒ Object
30 31 32 |
# File 'lib/qs/io_pipe.rb', line 30 def write(value) @writer.write_nonblock(value[0, NUMBER_OF_BYTES]) end |