Class: Infrastruct::BlockingQueue
- Inherits:
-
Object
- Object
- Infrastruct::BlockingQueue
- Defined in:
- lib/infrastruct/blocking_queue.rb
Instance Method Summary collapse
-
#initialize ⇒ BlockingQueue
constructor
A new instance of BlockingQueue.
- #pop ⇒ Object
- #push(element) ⇒ Object
- #unblock! ⇒ Object
Constructor Details
#initialize ⇒ BlockingQueue
Returns a new instance of BlockingQueue.
3 4 5 6 7 |
# File 'lib/infrastruct/blocking_queue.rb', line 3 def initialize @queue = ::Queue.new @mutex = Mutex.new @blocking = true end |
Instance Method Details
#pop ⇒ Object
13 14 15 16 17 |
# File 'lib/infrastruct/blocking_queue.rb', line 13 def pop @mutex.synchronize do @queue.pop(!@blocking) end end |
#push(element) ⇒ Object
9 10 11 |
# File 'lib/infrastruct/blocking_queue.rb', line 9 def push(element) @queue.push(element) end |
#unblock! ⇒ Object
19 20 21 22 23 |
# File 'lib/infrastruct/blocking_queue.rb', line 19 def unblock! @mutex.synchronize do @blocking = false end end |