Class: ConcurrentWorker::RequestCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/concurrent_worker/common.rb

Instance Method Summary collapse

Constructor Details

#initializeRequestCounter

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

#closeObject



36
37
38
# File 'lib/concurrent_worker/common.rb', line 36

def close
  @count.close
end

#closed?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/concurrent_worker/common.rb', line 40

def closed?
  @count.closed?
end

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/concurrent_worker/common.rb', line 28

def empty?
  @count.empty?
end

#popObject



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

#sizeObject



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