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+.
Public Class methods
new(*)
[show source]
# File lib/httpx/plugins/stream_bidi.rb 90 def initialize(*) 91 super 92 @parent_thread = Thread.current 93 @oob_mutex = Thread::Mutex.new 94 @oob_buffer = "".b 95 end
Public Instance methods
<<(chunk)
buffers the chunk
to be sent
[show source]
# File lib/httpx/plugins/stream_bidi.rb 98 def <<(chunk) 99 return super if Thread.current == @parent_thread 100 101 @oob_mutex.synchronize { @oob_buffer << chunk } 102 end
rebuffer()
reconciles the main and secondary buffer (which receives data from other threads).
[show source]
# File lib/httpx/plugins/stream_bidi.rb 105 def rebuffer 106 raise Error, "can only rebuffer while waiting on a response" unless Thread.current == @parent_thread 107 108 @oob_mutex.synchronize do 109 @buffer << @oob_buffer 110 @oob_buffer.clear 111 end 112 end