Sha256: 0add6870d5c78fba53e4304a5b9b2639c3d6f49196b3e1e739b926b56a177d94
Contents?: true
Size: 582 Bytes
Versions: 16
Compression:
Stored size: 582 Bytes
Contents
# frozen_string_literal: true module WaterDrop # Extra internal helper objects module Helpers # Atomic counter that we can safely increment and decrement without race conditions class Counter # @return [Integer] current value attr_reader :value def initialize @value = 0 @mutex = Mutex.new end # Increments the value by 1 def increment @mutex.synchronize { @value += 1 } end # Decrements the value by 1 def decrement @mutex.synchronize { @value -= 1 } end end end end
Version data entries
16 entries across 16 versions & 1 rubygems