Class: ConcurrentWorker::RequestCounter
- Inherits:
-
Object
- Object
- ConcurrentWorker::RequestCounter
- Defined in:
- lib/concurrent_worker/common.rb
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize ⇒ RequestCounter
constructor
A new instance of RequestCounter.
- #pop ⇒ Object
- #push(args) ⇒ Object
- #rest ⇒ 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
30 31 32 |
# File 'lib/concurrent_worker/common.rb', line 30 def close @count.close end |
#closed? ⇒ Boolean
34 35 36 |
# File 'lib/concurrent_worker/common.rb', line 34 def closed? @count.closed? end |
#pop ⇒ Object
13 14 15 16 17 18 |
# File 'lib/concurrent_worker/common.rb', line 13 def pop Thread.handle_interrupt(Object => :never) do @count.pop @com.push(true) end end |
#push(args) ⇒ Object
10 11 12 |
# File 'lib/concurrent_worker/common.rb', line 10 def push(args) @count.push(args) end |
#rest ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/concurrent_worker/common.rb', line 38 def rest result = [] until @count.empty? req = @count.pop next if req == [] result.push(req) end result end |
#size ⇒ Object
26 27 28 |
# File 'lib/concurrent_worker/common.rb', line 26 def size @count.size end |
#wait_until_less_than(n) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/concurrent_worker/common.rb', line 20 def wait_until_less_than(n) return if @count.size < n while @com.pop break if @count.size < n end end |