class Leafy::Core::Counter

Public Class Methods

new() click to toggle source
# File lib/leafy/core/counter.rb, line 7
def initialize
  @count = Concurrent::ThreadSafe::Util::Adder.new
end

Public Instance Methods

count() click to toggle source

Returns the counter's current value.

@return the counter's current value

# File lib/leafy/core/counter.rb, line 28
def count
  @count.sum
end
dec(n = 1) click to toggle source

Decrement the counter by {@code n}, default by one.

@param n the amount by which the counter will be decreased

# File lib/leafy/core/counter.rb, line 21
def dec(n = 1)
  @count.add(-n)
end
inc(n = 1) click to toggle source

Increment the counter by {@code n}, default by one.

@param n the amount by which the counter will be increased

# File lib/leafy/core/counter.rb, line 14
def inc(n = 1)
  @count.add(n)
end