Class: ActionPool::Queue
- Inherits:
-
Queue
- Object
- Queue
- ActionPool::Queue
- Defined in:
- lib/actionpool/Queue.rb
Overview
Adds a little bit extra functionality to the Queue class
Instance Method Summary collapse
-
#clear ⇒ Object
Clear queue.
-
#initialize ⇒ Queue
constructor
Create a new Queue for the ActionPool::Pool.
-
#pause ⇒ Object
Stop the queue from returning results to requesting threads.
-
#pop ⇒ Object
Check if queue needs to wait before returning.
-
#unpause ⇒ Object
Allow the queue to return results.
-
#wait_empty ⇒ Object
Park a thread here until queue is empty.
Constructor Details
#initialize ⇒ Queue
Create a new Queue for the ActionPool::Pool
7 8 9 10 11 12 13 14 |
# File 'lib/actionpool/Queue.rb', line 7 def initialize super @wait = false @pause_lock = Mutex.new @empty_lock = Mutex.new @pause_guard = ConditionVariable.new @empty_guard = ConditionVariable.new end |
Instance Method Details
#clear ⇒ Object
Clear queue
40 41 42 43 44 45 |
# File 'lib/actionpool/Queue.rb', line 40 def clear super @empty_lock.synchronize do @empty_guard.broadcast end end |
#pause ⇒ Object
Stop the queue from returning results to requesting threads. Threads will wait for results until signalled
17 18 19 |
# File 'lib/actionpool/Queue.rb', line 17 def pause @pause_lock.synchronize{@wait = true} end |
#pop ⇒ Object
Check if queue needs to wait before returning
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/actionpool/Queue.rb', line 29 def pop @pause_lock.synchronize do @pause_guard.wait(@pause_lock) if @wait end o = super @empty_lock.synchronize do @empty_guard.broadcast if empty? end return o end |
#unpause ⇒ Object
Allow the queue to return results. Any threads waiting will have results given to them.
22 23 24 25 26 27 |
# File 'lib/actionpool/Queue.rb', line 22 def unpause @pause_lock.synchronize do @wait = false @pause_guard.broadcast end end |
#wait_empty ⇒ Object
Park a thread here until queue is empty
47 48 49 50 51 |
# File 'lib/actionpool/Queue.rb', line 47 def wait_empty @empty_lock.synchronize do @empty_guard.wait(@empty_lock) if size > 0 end end |