Class: ConcurrentWorker::RequestCounter
- Inherits:
-
Object
- Object
- ConcurrentWorker::RequestCounter
- Defined in:
- lib/concurrent_worker/common.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize ⇒ RequestCounter
constructor
A new instance of RequestCounter.
- #pop ⇒ Object
- #push(args) ⇒ Object
- #size ⇒ Object
- #wait_until_less_than(n) ⇒ Object
Constructor Details
#initialize ⇒ RequestCounter
Returns a new instance of RequestCounter.
6 7 8 9 |
# File 'lib/concurrent_worker/common.rb', line 6 def initialize @count = Queue.new @com = Queue.new end |
Instance Method Details
#close ⇒ Object
36 37 38 |
# File 'lib/concurrent_worker/common.rb', line 36 def close @count.close end |
#closed? ⇒ Boolean
40 41 42 |
# File 'lib/concurrent_worker/common.rb', line 40 def closed? @count.closed? end |
#empty? ⇒ Boolean
28 29 30 |
# File 'lib/concurrent_worker/common.rb', line 28 def empty? @count.empty? end |
#pop ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/concurrent_worker/common.rb', line 13 def pop Thread.handle_interrupt(Object => :never) do r = @count.pop @com.push(true) r end end |
#push(args) ⇒ Object
10 11 12 |
# File 'lib/concurrent_worker/common.rb', line 10 def push(args) @count.push(args) end |
#size ⇒ Object
32 33 34 |
# File 'lib/concurrent_worker/common.rb', line 32 def size @count.size end |
#wait_until_less_than(n) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/concurrent_worker/common.rb', line 21 def wait_until_less_than(n) return if @count.size < n while @com.pop break if @count.size < n end end |