Class: BlockingQueue
- Inherits:
-
Object
- Object
- BlockingQueue
- Defined in:
- lib/wattics-api-client/blocking_queue.rb
Direct Known Subclasses
Instance Method Summary collapse
- #<<(x) ⇒ Object
-
#initialize ⇒ BlockingQueue
constructor
A new instance of BlockingQueue.
- #is_empty? ⇒ Boolean
- #pop ⇒ Object
Constructor Details
#initialize ⇒ BlockingQueue
Returns a new instance of BlockingQueue.
2 3 4 5 6 |
# File 'lib/wattics-api-client/blocking_queue.rb', line 2 def initialize @mutex = Mutex.new @queue = [] @received = ConditionVariable.new end |
Instance Method Details
#<<(x) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/wattics-api-client/blocking_queue.rb', line 8 def <<(x) @mutex.synchronize do @queue << x @received.signal end end |
#is_empty? ⇒ Boolean
22 23 24 |
# File 'lib/wattics-api-client/blocking_queue.rb', line 22 def is_empty? @queue.empty? end |
#pop ⇒ Object
15 16 17 18 19 20 |
# File 'lib/wattics-api-client/blocking_queue.rb', line 15 def pop @mutex.synchronize do @received.wait(@mutex) while is_empty? @queue.shift end end |