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 |
# File 'lib/actionpool/Queue.rb', line 7 def initialize super @wait = false @pause_guard = Splib::Monitor.new @empty_guard = Splib::Monitor.new end |
Instance Method Details
#clear ⇒ Object
Clear queue
32 33 34 35 |
# File 'lib/actionpool/Queue.rb', line 32 def clear super @empty_guard.broadcast end |
#pause ⇒ Object
Stop the queue from returning results to requesting threads. Threads will wait for results until signalled
15 16 17 |
# File 'lib/actionpool/Queue.rb', line 15 def pause @wait = true end |
#pop ⇒ Object
Check if queue needs to wait before returning
25 26 27 28 29 30 |
# File 'lib/actionpool/Queue.rb', line 25 def pop @pause_guard.wait_while{ @wait } o = super @empty_guard.broadcast if empty? return o end |
#unpause ⇒ Object
Allow the queue to return results. Any threads waiting will have results given to them.
20 21 22 23 |
# File 'lib/actionpool/Queue.rb', line 20 def unpause @wait = false @pause_guard.broadcast end |
#wait_empty ⇒ Object
Park a thread here until queue is empty
37 38 39 |
# File 'lib/actionpool/Queue.rb', line 37 def wait_empty @empty_guard.wait_while{ size > 0 } end |