Class: Async::HTTP::Protocol::HTTP2::Output
- Inherits:
-
Object
- Object
- Async::HTTP::Protocol::HTTP2::Output
- Defined in:
- lib/async/http/protocol/http2/output.rb
Instance Attribute Summary collapse
-
#trailer ⇒ Object
readonly
Returns the value of attribute trailer.
Instance Method Summary collapse
-
#close(error = nil) ⇒ Object
This method should only be called from within the context of the output task.
-
#initialize(stream, body, trailer = nil) ⇒ Output
constructor
A new instance of Output.
- #start(parent: Task.current) ⇒ Object
-
#stop(error) ⇒ Object
This method should only be called from within the context of the HTTP/2 stream.
- #window_updated(size) ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize(stream, body, trailer = nil) ⇒ Output
Returns a new instance of Output.
13 14 15 16 17 18 19 20 21 |
# File 'lib/async/http/protocol/http2/output.rb', line 13 def initialize(stream, body, trailer = nil) @stream = stream @body = body @trailer = trailer @task = nil @window_updated = Async::Condition.new end |
Instance Attribute Details
#trailer ⇒ Object (readonly)
Returns the value of attribute trailer.
23 24 25 |
# File 'lib/async/http/protocol/http2/output.rb', line 23 def trailer @trailer end |
Instance Method Details
#close(error = nil) ⇒ Object
This method should only be called from within the context of the output task.
54 55 56 57 58 59 |
# File 'lib/async/http/protocol/http2/output.rb', line 54 def close(error = nil) if @stream @stream.finish_output(error) @stream = nil end end |
#start(parent: Task.current) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/async/http/protocol/http2/output.rb', line 25 def start(parent: Task.current) raise "Task already started!" if @task if @body.stream? @task = parent.async(&self.method(:stream)) else @task = parent.async(&self.method(:passthrough)) end end |
#stop(error) ⇒ Object
This method should only be called from within the context of the HTTP/2 stream.
62 63 64 65 |
# File 'lib/async/http/protocol/http2/output.rb', line 62 def stop(error) @task&.stop @task = nil end |
#window_updated(size) ⇒ Object
35 36 37 |
# File 'lib/async/http/protocol/http2/output.rb', line 35 def window_updated(size) @window_updated.signal end |
#write(chunk) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/async/http/protocol/http2/output.rb', line 39 def write(chunk) until chunk.empty? maximum_size = @stream.available_frame_size while maximum_size <= 0 @window_updated.wait maximum_size = @stream.available_frame_size end break unless chunk = send_data(chunk, maximum_size) end end |