We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3bdd372 commit d510574Copy full SHA for d510574
lib/resque/consumer.rb
@@ -1,17 +1,23 @@
1
module Resque
2
class Consumer
3
class Latch # :nodoc:
4
- def initialize
5
- @mutex = Mutex.new
6
- @cond = ConditionVariable.new
+ def initialize(count = 1)
+ @count = count
+ @lock = Monitor.new
7
+ @cv = @lock.new_cond
8
end
9
10
def release
- @mutex.synchronize { @cond.broadcast }
11
+ @lock.synchronize do
12
+ @count -= 1 if @count > 0
13
+ @cv.broadcast if @count.zero?
14
+ end
15
16
17
def await
- @mutex.synchronize { @cond.wait @mutex }
18
19
+ @cv.wait_while { @count > 0 }
20
21
22
23
0 commit comments