Class: Skylight::Util::Clock Private

Inherits:
Object
  • Object
show all
Defined in:
lib/skylight/util/clock.rb,
ext/skylight_native.c

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A more precise clock

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.defaultObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
# File 'lib/skylight/util/clock.rb', line 49

def default
  @default ||= Clock.new
end

Class Method Details

.absolute_secsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
# File 'lib/skylight/util/clock.rb', line 37

def absolute_secs
  default.absolute_secs
end

.nanosObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



41
42
43
# File 'lib/skylight/util/clock.rb', line 41

def nanos
  default.nanos
end

.secsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
# File 'lib/skylight/util/clock.rb', line 45

def secs
  default.secs
end

.use_native!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



5
6
7
8
9
10
11
# File 'lib/skylight/util/clock.rb', line 5

def self.use_native!
  class_eval do
    def tick
      native_hrtime
    end
  end
end

Instance Method Details

#absolute_secsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: rename to secs



22
23
24
# File 'lib/skylight/util/clock.rb', line 22

def absolute_secs
  Time.now.to_i
end

#nanosObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: remove



27
28
29
# File 'lib/skylight/util/clock.rb', line 27

def nanos
  tick
end

#native_hrtimeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

class Skylight::Util::Clock



171
172
173
174
175
# File 'ext/skylight_native.c', line 171

static VALUE
clock_high_res_time(VALUE self) {
  UNUSED(self);
  return ULL2NUM(sky_hrtime());
}

#secsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: remove



32
33
34
# File 'lib/skylight/util/clock.rb', line 32

def secs
  nanos / 1_000_000_000
end

#tickObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Lint/DuplicateMethods



14
15
16
17
# File 'lib/skylight/util/clock.rb', line 14

def tick
  now = Time.now
  (now.to_i * 1_000_000_000) + (now.usec * 1_000)
end