Class: NetHttp2::Stream
- Inherits:
-
Object
- Object
- NetHttp2::Stream
- Defined in:
- lib/net-http2/stream.rb
Instance Method Summary collapse
- #async_call_with(request, &block) ⇒ Object
- #call_with(request) ⇒ Object
-
#initialize(options = {}) ⇒ Stream
constructor
A new instance of Stream.
Constructor Details
#initialize(options = {}) ⇒ Stream
Returns a new instance of Stream.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/net-http2/stream.rb', line 5 def initialize(={}) @h2_stream = [:h2_stream] @uri = [:uri] @headers = {} @data = '' @completed = false @block = nil @h2_stream.on(:headers) do |hs| hs.each { |k, v| @headers[k] = v } end @h2_stream.on(:data) { |d| @data << d } @h2_stream.on(:close) { mark_as_completed_and_async_respond } end |
Instance Method Details
#async_call_with(request, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/net-http2/stream.rb', line 26 def async_call_with(request, &block) @block = block send_data_of request Thread.new do wait(request.timeout) @block.call(nil) unless @completed end end |
#call_with(request) ⇒ Object
21 22 23 24 |
# File 'lib/net-http2/stream.rb', line 21 def call_with(request) send_data_of request sync_respond(request.timeout) end |