lib/spectator/counter.rb in netflix-spectator-rb-0.2.2 vs lib/spectator/counter.rb in netflix-spectator-rb-0.3.0

- old
+ new

@@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'spectator/atomic_number' -require 'spectator/measure' +require_relative 'atomic_number' +require_relative 'measure' module Spectator # A counter is used to measure the rate at which an event is occurring class Counter # Initialize a new instance setting its id, and starting the @@ -18,10 +18,15 @@ @count.add_and_get(delta) end # Get the current count as a list of Measure and reset the count to 0 def measure - [Measure.new(@id.with_stat('count'), @count.get_and_set(0))] + cnt = @count.get_and_set(0) + if cnt.positive? + [Measure.new(@id.with_default_stat('count'), cnt)] + else + [] + end end # Read the current count. Calls to measure will reset it def count @count.get