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

Version Path
waterdrop-2.8.2 lib/waterdrop/helpers/counter.rb
waterdrop-2.8.1 lib/waterdrop/helpers/counter.rb
waterdrop-2.8.0 lib/waterdrop/helpers/counter.rb
waterdrop-2.7.4 lib/waterdrop/helpers/counter.rb
waterdrop-2.7.3 lib/waterdrop/helpers/counter.rb
waterdrop-2.7.0 lib/waterdrop/helpers/counter.rb
waterdrop-2.7.0.rc2 lib/waterdrop/helpers/counter.rb
waterdrop-2.7.0.rc1 lib/waterdrop/helpers/counter.rb
waterdrop-2.7.0.beta2 lib/waterdrop/helpers/counter.rb
waterdrop-2.7.0.beta1 lib/waterdrop/helpers/counter.rb
waterdrop-2.7.0.alpha3 lib/waterdrop/helpers/counter.rb
waterdrop-2.7.0.alpha2 lib/waterdrop/helpers/counter.rb
waterdrop-2.7.0.alpha1 lib/waterdrop/helpers/counter.rb
waterdrop-2.6.14 lib/waterdrop/helpers/counter.rb
waterdrop-2.6.13 lib/waterdrop/helpers/counter.rb
waterdrop-2.6.12 lib/waterdrop/helpers/counter.rb