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



30
31
32
# File 'lib/concurrent_worker/common.rb', line 30

def close
  @count.close
end

#closed?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/concurrent_worker/common.rb', line 34

def closed?
  @count.closed?
end

#popObject



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

#restObject



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

#sizeObject



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