Sha256: c081f329eb3dd226011d5db58c2f980d4340bc9a4fb1a9f02aedc980432fa47c

Contents?: true

Size: 784 Bytes

Versions: 4

Compression:

Stored size: 784 Bytes

Contents

# frozen_string_literal: true

module Dry
  module Logger
    # @since 1.0.0
    # @api private
    class Clock
      # @since 1.0.0
      # @api private
      attr_reader :unit

      # @since 1.0.0
      # @api private
      def initialize(unit: :nanosecond)
        @unit = unit
      end

      # @since 1.0.0
      # @api private
      def now
        Time.now
      end

      # @since 1.0.0
      # @api private
      def now_utc
        now.getutc
      end

      # @since 1.0.0
      # @api private
      def measure
        start = current
        result = yield
        [result, current - start]
      end

      private

      # @since 1.0.0
      # @api private
      def current
        Process.clock_gettime(Process::CLOCK_MONOTONIC, unit)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-logger-1.0.3 lib/dry/logger/clock.rb
dry-logger-1.0.2 lib/dry/logger/clock.rb
dry-logger-1.0.1 lib/dry/logger/clock.rb
dry-logger-1.0.0 lib/dry/logger/clock.rb