Class: HTTPX::Plugins::StreamBidi::BidiBuffer
- Defined in:
- lib/httpx/plugins/stream_bidi.rb
Overview
BidiBuffer is a Buffer which can be receive data from threads othr than the thread of the corresponding Connection/Session.
It synchronizes access to a secondary internal @oob_buffer, which periodically is reconciled to the main internal @buffer.
Instance Attribute Summary
Attributes inherited from Buffer
Instance Method Summary collapse
-
#<<(chunk) ⇒ Object
buffers the
chunk
to be sent. -
#initialize ⇒ BidiBuffer
constructor
A new instance of BidiBuffer.
-
#rebuffer ⇒ Object
reconciles the main and secondary buffer (which receives data from other threads).
Methods inherited from Buffer
Constructor Details
#initialize ⇒ BidiBuffer
Returns a new instance of BidiBuffer.
90 91 92 93 94 95 |
# File 'lib/httpx/plugins/stream_bidi.rb', line 90 def initialize(*) super @parent_thread = Thread.current @oob_mutex = Thread::Mutex.new @oob_buffer = "".b end |
Instance Method Details
#<<(chunk) ⇒ Object
buffers the chunk
to be sent
98 99 100 101 102 |
# File 'lib/httpx/plugins/stream_bidi.rb', line 98 def <<(chunk) return super if Thread.current == @parent_thread @oob_mutex.synchronize { @oob_buffer << chunk } end |
#rebuffer ⇒ Object
reconciles the main and secondary buffer (which receives data from other threads).
105 106 107 108 109 110 111 112 |
# File 'lib/httpx/plugins/stream_bidi.rb', line 105 def rebuffer raise Error, "can only rebuffer while waiting on a response" unless Thread.current == @parent_thread @oob_mutex.synchronize do @buffer << @oob_buffer @oob_buffer.clear end end |