Sha256: 77082065c434e7ae19b08d12560c3ee34251bd7a02d24994fb85e8baaa7a8969

Contents?: true

Size: 1.35 KB

Versions: 110

Compression:

Stored size: 1.35 KB

Contents

require 'concurrent/synchronization'

module Concurrent

  class_definition = Class.new(Synchronization::LockableObject) do
    def initialize
      @last_time = Time.now.to_f
      super()
    end

    if defined?(Process::CLOCK_MONOTONIC)
      # @!visibility private
      def get_time
        Process.clock_gettime(Process::CLOCK_MONOTONIC)
      end
    elsif Concurrent.on_jruby?
      # @!visibility private
      def get_time
        java.lang.System.nanoTime() / 1_000_000_000.0
      end
    else

      # @!visibility private
      def get_time
        synchronize do
          now = Time.now.to_f
          if @last_time < now
            @last_time = now
          else # clock has moved back in time
            @last_time += 0.000_001
          end
        end
      end

    end
  end

  # Clock that cannot be set and represents monotonic time since
  # some unspecified starting point.
  #
  # @!visibility private
  GLOBAL_MONOTONIC_CLOCK = class_definition.new
  private_constant :GLOBAL_MONOTONIC_CLOCK

  # @!macro monotonic_get_time
  #
  #   Returns the current time a tracked by the application monotonic clock.
  #
  #   @return [Float] The current monotonic time since some unspecified
  #     starting point
  #
  #   @!macro monotonic_clock_warning
  def monotonic_time
    GLOBAL_MONOTONIC_CLOCK.get_time
  end

  module_function :monotonic_time
end

Version data entries

110 entries across 98 versions & 23 rubygems

Version Path
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.4/lib/concurrent/utility/monotonic_time.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.3/lib/concurrent/utility/monotonic_time.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
spiral_form-0.1.1 vendor/bundle/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
spiral_form-0.1.0 vendor/bundle/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
zuora_connect_ui-0.7.0 vendor/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
ric-0.13.0 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
ric-0.12.2 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/concurrent-ruby-1.1.5/lib/concurrent/utility/monotonic_time.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.4/lib/concurrent/utility/monotonic_time.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.3/lib/concurrent/utility/monotonic_time.rb
concurrent-ruby-1.1.5 lib/concurrent/utility/monotonic_time.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/concurrent-ruby-1.1.3/lib/concurrent/utility/monotonic_time.rb