Class: WebsocketSequentialClient::ReadQueue
- Inherits:
-
Object
- Object
- WebsocketSequentialClient::ReadQueue
- Defined in:
- lib/websocket_sequential_client/read_queue.rb
Instance Method Summary collapse
- #available? ⇒ Boolean
- #close(value) ⇒ Object
-
#initialize ⇒ ReadQueue
constructor
A new instance of ReadQueue.
- #pop ⇒ Object
- #push(frame) ⇒ Object
Constructor Details
#initialize ⇒ ReadQueue
Returns a new instance of ReadQueue.
7 8 9 10 11 12 |
# File 'lib/websocket_sequential_client/read_queue.rb', line 7 def initialize @mutex = Mutex.new @cond_var = ConditionVariable.new @frame_list = [] @closed_value = nil end |
Instance Method Details
#available? ⇒ Boolean
21 22 23 24 25 |
# File 'lib/websocket_sequential_client/read_queue.rb', line 21 def available? @mutex.synchronize do return !(@frame_list.empty?) end end |
#close(value) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/websocket_sequential_client/read_queue.rb', line 14 def close value @mutex.synchronize do @closed_value = value @cond_var.broadcast end end |
#pop ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/websocket_sequential_client/read_queue.rb', line 36 def pop @mutex.synchronize do until !(@frame_list.empty?) or @closed_value @cond_var.wait @mutex end if @frame_list.empty? return @closed_value else return @frame_list.shift end end end |
#push(frame) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/websocket_sequential_client/read_queue.rb', line 27 def push frame @mutex.synchronize do return if @closed_value @frame_list.push frame @cond_var.broadcast end end |