Class: LLM::Pipe
- Inherits:
-
Object
- Object
- LLM::Pipe
- Defined in:
- lib/llm/pipe.rb
Overview
The LLM::Pipe class wraps a pair of IO objects created by ‘IO.pipe`. It is used by llm.rb internals to manage process and stream communication through one small interface.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#close ⇒ void
Closes both ends of the pipe.
-
#close_reader ⇒ void
Closes the reader.
-
#close_writer ⇒ void
Closes the writer.
-
#closed? ⇒ Boolean
Returns true when both ends are closed.
-
#flush ⇒ void
Flushes the writer.
-
#initialize(binmode: false) ⇒ LLM::Pipe
constructor
Returns a new pipe.
-
#read_nonblock ⇒ String
Reads from the reader end without blocking.
-
#write ⇒ Integer
Writes to the writer.
Constructor Details
#initialize(binmode: false) ⇒ LLM::Pipe
Returns a new pipe.
24 25 26 27 |
# File 'lib/llm/pipe.rb', line 24 def initialize(binmode: false) @r, @w = IO.pipe [@r, @w].each(&:binmode) if binmode end |
Instance Attribute Details
#r ⇒ IO (readonly)
Returns the reader
12 13 14 |
# File 'lib/llm/pipe.rb', line 12 def r @r end |
#w ⇒ IO (readonly)
Returns the writer
17 18 19 |
# File 'lib/llm/pipe.rb', line 17 def w @w end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Closes both ends of the pipe.
62 63 64 65 |
# File 'lib/llm/pipe.rb', line 62 def close [@r, @w].each(&:close) rescue IOError end |
#close_reader ⇒ void
This method returns an undefined value.
Closes the reader.
70 71 72 73 |
# File 'lib/llm/pipe.rb', line 70 def close_reader @r.close rescue IOError end |
#close_writer ⇒ void
This method returns an undefined value.
Closes the writer.
78 79 80 81 |
# File 'lib/llm/pipe.rb', line 78 def close_writer @w.close rescue IOError end |
#closed? ⇒ Boolean
Returns true when both ends are closed.
55 56 57 |
# File 'lib/llm/pipe.rb', line 55 def closed? [@r, @w].all?(&:closed?) end |
#flush ⇒ void
This method returns an undefined value.
Flushes the writer.
48 49 50 |
# File 'lib/llm/pipe.rb', line 48 def flush @w.flush end |
#read_nonblock ⇒ String
Reads from the reader end without blocking.
34 35 36 |
# File 'lib/llm/pipe.rb', line 34 def read_nonblock(...) @r.read_nonblock(...) end |
#write ⇒ Integer
Writes to the writer.
41 42 43 |
# File 'lib/llm/pipe.rb', line 41 def write(...) @w.write(...) end |