Class: Connect::StreamResponse
- Inherits:
-
Object
- Object
- Connect::StreamResponse
- Includes:
- Enumerable
- Defined in:
- lib/connect/stream_response.rb
Constant Summary collapse
- END_OF_STREAM_FLAG =
0b00000010
Instance Attribute Summary collapse
- #error ⇒ Object readonly
-
#header ⇒ Object
readonly
Returns the value of attribute header.
- #trailer ⇒ Object readonly
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(header:, enumerator:) ⇒ StreamResponse
constructor
A new instance of StreamResponse.
- #stream_exhausted? ⇒ Boolean
Constructor Details
#initialize(header:, enumerator:) ⇒ StreamResponse
Returns a new instance of StreamResponse.
11 12 13 14 15 16 17 |
# File 'lib/connect/stream_response.rb', line 11 def initialize(header:, enumerator:) @header = header @enumerator = enumerator @trailer = nil @error = nil @stream_exhausted = false end |
Instance Attribute Details
#error ⇒ Object
37 38 39 40 41 |
# File 'lib/connect/stream_response.rb', line 37 def error raise StreamReadError, "Cannot read error before stream is exhausted" unless stream_exhausted? @error end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
9 10 11 |
# File 'lib/connect/stream_response.rb', line 9 def header @header end |
#trailer ⇒ Object
31 32 33 34 35 |
# File 'lib/connect/stream_response.rb', line 31 def trailer raise StreamReadError, "Cannot read trailer before stream is exhausted" unless stream_exhausted? @trailer end |
Instance Method Details
#each(&block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/connect/stream_response.rb', line 19 def each(&block) enumerator.each do |flags, | if flags & END_OF_STREAM_FLAG == 0 yield else () end end raise InvalidStreamResponseError, "Stream did not end with end stream message" unless stream_exhausted? end |
#stream_exhausted? ⇒ Boolean
43 44 45 |
# File 'lib/connect/stream_response.rb', line 43 def stream_exhausted? @stream_exhausted end |