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