monotime 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 388a55af121b75e9a9ac06db8674e5a8a4b06ade0431a5cdd961f82426c87ade
4
- data.tar.gz: 7d62a9b673252f01591769d8659c5a36b1026088724a2afc9694b41f633ca053
3
+ metadata.gz: 207159be0c76004c8676ac860106cd133344a29ca0021decbc14bc7448a17fab
4
+ data.tar.gz: 89c97583a40bfe82dd7c822cfd9a165be19c796cdf32396ee49ef861bbf7fb32
5
5
  SHA512:
6
- metadata.gz: 14c7ede1fc2daa4fef854d3be58392f57849ff07c4f815c3e995f32073e14893fa7ad95f08e074199457517d262fc8c2942316b8039260b1e66e4045409bb6cf
7
- data.tar.gz: b2c907ce1b4f3f92185ba4cb238c3809b465d40be7e34eb1c4a225779a4f6c156ae1d78742ddf24a467d59bfd3437c15be54d4f8bc91a9a9d06fa42ee5e5544a
6
+ metadata.gz: c3aa917f832adedaa98acca61c58858d9e4ce57922d3ba457921b2e2c8adc023875a328c308258555f38dbb482168da73f7488c6306bd9751089b3ef21f5e7b0
7
+ data.tar.gz: b340008fa59637177c6c3caad1d4f5816ba8626a533993d3cc8de615b4c12899b3939e4338f6dae04d66fa09c90e6d7de06667cd02af915c2717bef7fca9aa25
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.1] - 2023-09-18
4
+
5
+ ### Changed
6
+
7
+ - After further consideration, return to defaulting to `CLOCK_MONOTONIC` instead
8
+ of the overly-elaborate auto-selection introduced in 0.8.0.
9
+
10
+ ### Removed
11
+
12
+ - `Instant.clock_name`. No I'm not incrementing to 0.9. It's been a few hours,
13
+ you're not using it, shut up.
14
+
3
15
  ## [0.8.0] - 2023-09-17
4
16
 
5
17
  ### Added
@@ -165,8 +177,10 @@
165
177
  [0.6.1]: https://github.com/Freaky/monotime/commits/v0.6.1
166
178
  [0.7.0]: https://github.com/Freaky/monotime/commits/v0.7.0
167
179
  [0.7.1]: https://github.com/Freaky/monotime/commits/v0.7.0
168
- [0.8.0]: https://github.com/Freaky/monotime/commits/v0.7.0
180
+ [0.8.0]: https://github.com/Freaky/monotime/commits/v0.8.0
181
+ [0.8.1]: https://github.com/Freaky/monotime/commits/v0.8.1
169
182
  [issue #1]: https://github.com/Freaky/monotime/issues/1
183
+ [Ruby #16740]: https://bugs.ruby-lang.org/issues/16740
170
184
  [@celsworth]: https://github.com/celsworth
171
185
  [@petergoldstein]: https://github.com/petergoldstein
172
- [@fig]: https://github.com/fig
186
+ [@fig]: https://github.com/fig
@@ -12,38 +12,16 @@ module Monotime
12
12
  include Comparable
13
13
 
14
14
  class << self
15
- attr_writer :clock_id
16
-
17
- # The symbolic name of the automatically-selected +Process.clock_gettime+
18
- # clock id, if available. This will *not* reflect a manually-set +clock_id+.
19
- #
20
- # @return [Symbol, nil]
21
- attr_reader :clock_name
22
-
23
- # The function used to create +Instant+ instances.
24
- #
25
- # This function must return a +Numeric+, monotonic count of nanoseconds
26
- # since a fixed point in the past.
27
- #
28
- # Defaults to `lambda { Process.clock_gettime(clock_id, :nanosecond) }`.
29
- #
30
- # @overload monotonic_function=(function)
31
- # @param function [#call]
32
- attr_accessor :monotonic_function
33
-
34
15
  # @overload clock_id
35
- # The configured or detected +Process.clock_getime+ clock identifier.
36
- #
37
- # Raises +NotImplementedError+ if a suitable monotonic clock source cannot
38
- # be found and one has not been specified manually.
16
+ # The +Process.clock_gettime+ clock id used to create +Instant+ instances
17
+ # by the default monotonic function.
39
18
  #
40
19
  # @return [Numeric]
41
20
  #
42
21
  # @overload clock_id=(id)
43
- # The +Process.clock_gettime+ clock id used to create +Instant+ instances
44
- # by the default monotonic function.
45
22
  #
46
- # Suggested options include but are not limited to:
23
+ # Override the default +Process.clock_gettime+ clock id. Some potential
24
+ # choices include but are not limited to:
47
25
  #
48
26
  # * +Process::CLOCK_MONOTONIC_RAW+
49
27
  # * +Process::CLOCK_UPTIME_RAW+
@@ -55,54 +33,44 @@ module Monotime
55
33
  # * +Process::CLOCK_MONOTONIC+
56
34
  #
57
35
  # These are platform-dependant and may vary in resolution, performance,
58
- # and behaviour from NTP frequency skew and system suspend/resume.
36
+ # and behaviour from NTP frequency skew and system suspend/resume, and
37
+ # should be selected with care.
59
38
  #
60
39
  # It is possible to set non-monotonic clock sources here. You probably
61
40
  # shouldn't.
62
41
  #
63
- # Defaults to auto-detect.
42
+ # Defaults to +Process::CLOCK_MONOTONIC+.
64
43
  #
65
44
  # @param id [Numeric]
66
- def clock_id
67
- @clock_id ||= detect_clock_id
68
- end
45
+ attr_accessor :clock_id
46
+
47
+ # The function used to create +Instant+ instances.
48
+ #
49
+ # This function must return a +Numeric+, monotonic count of nanoseconds
50
+ # since a fixed point in the past.
51
+ #
52
+ # Defaults to +-> { Process.clock_gettime(clock_id, :nanosecond) }+.
53
+ #
54
+ # @overload monotonic_function=(function)
55
+ # @param function [#call]
56
+ attr_accessor :monotonic_function
69
57
 
70
58
  # Return the claimed resolution of the given clock id or the configured
71
59
  # +clock_id+, as a +Duration+, or +nil+ if invalid.
72
60
  #
61
+ # Note per Ruby issue #16740, the practical usability of this method is
62
+ # dubious and non-portable.
63
+ #
73
64
  # @param clock [Numeric] Optional clock id instead of default.
74
- def clock_getres(clock = @clock_id)
65
+ def clock_getres(clock = clock_id)
75
66
  Duration.from_nanos(Process.clock_getres(clock, :nanosecond))
76
67
  rescue SystemCallError
77
68
  # suppress errors
78
69
  end
79
-
80
- private
81
-
82
- def detect_clock_id
83
- name, id, =
84
- [
85
- :CLOCK_MONOTONIC_RAW, # Linux, not affected by NTP frequency adjustments
86
- :CLOCK_UPTIME_RAW, # macOS, not affected by NTP frequency adjustments
87
- :CLOCK_UPTIME_PRECISE, # FreeBSD, increments while system is running
88
- :CLOCK_UPTIME, # OpenBSD, increments while system is running
89
- :CLOCK_MONOTONIC_PRECISE, # FreeBSD, precise monotonic clock
90
- :CLOCK_MONOTONIC, # Standard cross-platform monotonic clock
91
- ]
92
- .each_with_index # Used to force a stable sort in min_by
93
- .filter { |name, _| Process.const_defined?(name) }
94
- .map { |name, index| [name, Process.const_get(name), index] }
95
- .filter_map { |clock| clock.insert(2, clock_getres(clock[1])) }
96
- .min_by { |clock| clock[2..] } # find smallest resolution and index
97
- .tap { |clock| raise NotImplementedError, 'No usable clock' unless clock }
98
-
99
- @clock_name = name
100
- id
101
- end
102
70
  end
103
71
 
104
72
  self.monotonic_function = -> { Process.clock_gettime(clock_id, :nanosecond) }
105
- clock_id # detect our clock_id early
73
+ self.clock_id = Process::CLOCK_MONOTONIC
106
74
 
107
75
  # Create a new +Instant+ from an optional nanosecond measurement.
108
76
  #
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Monotime
4
4
  # Version of the `monotime` gem
5
- MONOTIME_VERSION = '0.8.0'
5
+ MONOTIME_VERSION = '0.8.1'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monotime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Hurst
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-17 00:00:00.000000000 Z
11
+ date: 2023-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.4.19
112
+ rubygems_version: 3.4.18
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: A sensible interface to the monotonic clock