class Sidekiq::Processor::Counter
Ruby doesn't provide atomic counters out of the box so we'll implement something simple ourselves. bugs.ruby-lang.org/issues/14706
Public Class Methods
new()
click to toggle source
# File lib/sidekiq/processor.rb, line 199 def initialize @value = 0 @lock = Mutex.new end
Public Instance Methods
incr(amount=1)
click to toggle source
# File lib/sidekiq/processor.rb, line 204 def incr(amount=1) @lock.synchronize { @value = @value + amount } end
reset()
click to toggle source
# File lib/sidekiq/processor.rb, line 208 def reset @lock.synchronize { val = @value; @value = 0; val } end