Class: ThrottleQueue::PriorityQueue
- Inherits:
-
Object
- Object
- ThrottleQueue::PriorityQueue
- Defined in:
- lib/throttle-queue/single-process.rb
Overview
:nodoc: all
Instance Method Summary collapse
- #background(id) ⇒ Object
- #empty? ⇒ Boolean
- #foreground(id) ⇒ Object
-
#initialize ⇒ PriorityQueue
constructor
A new instance of PriorityQueue.
- #pop ⇒ Object
- #shutdown ⇒ Object
- #shutdown? ⇒ Boolean
Constructor Details
#initialize ⇒ PriorityQueue
Returns a new instance of PriorityQueue.
164 165 166 167 168 169 170 |
# File 'lib/throttle-queue/single-process.rb', line 164 def initialize @mutex = Mutex.new @fg = [] @bg = [] @received = ConditionVariable.new @shutdown = false end |
Instance Method Details
#background(id) ⇒ Object
187 188 189 190 191 192 193 194 |
# File 'lib/throttle-queue/single-process.rb', line 187 def background(id) @mutex.synchronize { unless @shutdown || @bg.include?(id) @bg << id @received.signal end } end |
#empty? ⇒ Boolean
181 182 183 184 185 |
# File 'lib/throttle-queue/single-process.rb', line 181 def empty? @mutex.synchronize { @fg.empty? and @bg.empty? } end |
#foreground(id) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/throttle-queue/single-process.rb', line 196 def foreground(id) @mutex.synchronize { unless @shutdown || @fg.include?(id) @fg << id if @bg.include?(id) @bg.delete id else @received.signal end end } end |
#pop ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/throttle-queue/single-process.rb', line 209 def pop @mutex.synchronize { if @fg.empty? and @bg.empty? @received.wait(@mutex) unless @shutdown end if @shutdown elsif ! @fg.empty? @fg.shift else @bg.shift end } end |
#shutdown ⇒ Object
172 173 174 175 |
# File 'lib/throttle-queue/single-process.rb', line 172 def shutdown @shutdown = true @received.signal end |
#shutdown? ⇒ Boolean
177 178 179 |
# File 'lib/throttle-queue/single-process.rb', line 177 def shutdown? @shutdown end |