class WaterDrop::Helpers::Counter
Atomic counter that we can safely increment and decrement without race conditions
Attributes
@return [Integer] current value
Public Class Methods
Source
# File lib/waterdrop/helpers/counter.rb, line 11 def initialize @value = 0 @mutex = Mutex.new end
Public Instance Methods
Source
# File lib/waterdrop/helpers/counter.rb, line 22 def decrement @mutex.synchronize { @value -= 1 } end
Decrements the value by 1
Source
# File lib/waterdrop/helpers/counter.rb, line 17 def increment @mutex.synchronize { @value += 1 } end
Increments the value by 1