Class: WebsocketSequentialClient::WriteQueue
- Inherits:
-
Object
- Object
- WebsocketSequentialClient::WriteQueue
- Defined in:
- lib/websocket_sequential_client/write_queue.rb
Overview
:nodoc:
Instance Method Summary collapse
- #close(value) ⇒ Object
-
#initialize ⇒ WriteQueue
constructor
A new instance of WriteQueue.
- #pop ⇒ Object
- #pop_result(frame) ⇒ Object
- #process_frame(frame) ⇒ Object
- #push(frame) ⇒ Object
- #push_result(frame, result) ⇒ Object
Constructor Details
#initialize ⇒ WriteQueue
Returns a new instance of WriteQueue.
7 8 9 10 11 12 13 14 15 |
# File 'lib/websocket_sequential_client/write_queue.rb', line 7 def initialize @mutex = Mutex.new @cond_var = ConditionVariable.new @result_mutex = Mutex.new @result_cond_var = ConditionVariable.new @frame_list = [] @frame_result = {} @closed_value = nil end |
Instance Method Details
#close(value) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/websocket_sequential_client/write_queue.rb', line 17 def close value @result_mutex.synchronize do @closed_value = value @result_cond_var.broadcast end end |
#pop ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/websocket_sequential_client/write_queue.rb', line 33 def pop @mutex.synchronize do @cond_var.wait @mutex while @frame_list.empty? return @frame_list.shift end end |
#pop_result(frame) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/websocket_sequential_client/write_queue.rb', line 50 def pop_result frame @result_mutex.synchronize do until @frame_result.key?(frame.object_id) or @closed_value @result_cond_var.wait @result_mutex end return (@frame_result.delete(frame.object_id) || @closed_value) end end |
#process_frame(frame) ⇒ Object
60 61 62 63 |
# File 'lib/websocket_sequential_client/write_queue.rb', line 60 def process_frame frame push frame pop_result frame end |
#push(frame) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/websocket_sequential_client/write_queue.rb', line 24 def push frame return if @closed_value @mutex.synchronize do @frame_list.push frame @cond_var.broadcast end end |
#push_result(frame, result) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/websocket_sequential_client/write_queue.rb', line 41 def push_result frame, result @result_mutex.synchronize do return if @closed_value @frame_result[frame.object_id] = result @result_cond_var.broadcast end end |