Class: ActionPool::Queue

Inherits:
Queue
  • Object
show all
Defined in:
lib/actionpool/Queue.rb

Overview

Adds a little bit extra functionality to the Queue class

Instance Method Summary collapse

Constructor Details

#initializeQueue

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

#clearObject

Clear queue



32
33
34
35
# File 'lib/actionpool/Queue.rb', line 32

def clear
    super
    @empty_guard.broadcast
end

#pauseObject

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

#popObject

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

#unpauseObject

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_emptyObject

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