philiprehberger-timeout_kit 0.2.1 → 0.3.0

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: 7a8adc873e824dbd74917d235e838e7471d7e8d5171dced00b3c551d6cd122c7
4
- data.tar.gz: c32d783deeb26085d274dd7e802f0127848ad14292d25bb90edc72f8dbe1112b
3
+ metadata.gz: 80b321def31fd94ffb7e7800f957ed9dcc2037245dfbe90a1213a2bad9e0366d
4
+ data.tar.gz: cdff9dc81339f285c3209a505644d0ed772943d415c9e58dd731a270b8e0b0db
5
5
  SHA512:
6
- metadata.gz: 41d90f277f055add991dede2a122ba767b109cc1d112526ef4aab0a217b935ad16df0e38ddf78ec78b9cc54de7e4d5c8b542b2b93d6f7c95908ed0deb3c7804a
7
- data.tar.gz: 39b256c071b1b339f37b02bb13c07ed76fe486b78006961178c6d6e56d0046c1f04dab90d102b0fd14aa3cfb5b6a343f239c92e654de13fa9ce79658e1c56f64
6
+ metadata.gz: 34fa84c7798b419ba9ba807ecd824a5f20f143cd304e4b96874648c8dec0de012461543ab3af08411898f05011c2967a23e5ff8a488acb88f3a83d35d710bc58
7
+ data.tar.gz: 2234c624205be2928d8dc09d5257222116d7983af96f88e4d05c3610baf02e7fceb2a5d80ffc8412375562f522f7e99e93ec0704e7106bb6bf0bbf77193828df
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0] - 2026-04-17
11
+
12
+ ### Added
13
+ - `Deadline#elapsed` returns seconds since the deadline was created (complement to `#remaining`)
14
+
10
15
  ## [0.2.1] - 2026-03-31
11
16
 
12
17
  ### Changed
data/README.md CHANGED
@@ -49,6 +49,16 @@ Philiprehberger::TimeoutKit.deadline(10) do |d|
49
49
  end
50
50
  ```
51
51
 
52
+ ### Measuring elapsed time
53
+
54
+ ```ruby
55
+ Philiprehberger::TimeoutKit.deadline(10) do |d|
56
+ do_work
57
+ puts "Work took #{d.elapsed}s so far"
58
+ # elapsed continues to grow past the budget even after expiration
59
+ end
60
+ ```
61
+
52
62
  ### Nested Deadlines
53
63
 
54
64
  ```ruby
@@ -140,6 +150,7 @@ end
140
150
  | `.current_deadline` | Return the current active deadline or nil |
141
151
  | `Deadline#check!` | Raise `DeadlineExceeded` if the deadline has passed (respects grace period) |
142
152
  | `Deadline#remaining` | Seconds remaining until the primary deadline (negative during grace) |
153
+ | `Deadline#elapsed` | Seconds elapsed since the deadline was created (continues past the budget after expiration) |
143
154
  | `Deadline#expired?` | Whether the primary deadline has passed |
144
155
  | `Deadline#name` | The human-readable name for this deadline (nil if not set) |
145
156
  | `Deadline#in_grace?` | Whether the deadline is in the grace period |
@@ -20,7 +20,8 @@ module Philiprehberger
20
20
  # @param grace [Numeric, nil] optional grace period in seconds after the primary deadline
21
21
  # @param on_expire [Proc, nil] optional callback that fires once when expiry is detected
22
22
  def initialize(seconds, name: nil, grace: nil, on_expire: nil)
23
- @expires_at = now + seconds
23
+ @started_at = now
24
+ @expires_at = @started_at + seconds
24
25
  @name = name
25
26
  @grace_seconds = grace
26
27
  @grace_expires_at = @grace_seconds ? @expires_at + @grace_seconds : nil
@@ -65,6 +66,16 @@ module Philiprehberger
65
66
  end
66
67
  end
67
68
 
69
+ # Return the number of seconds elapsed since the deadline was created.
70
+ # This is a pure wall-clock reading from the monotonic clock and continues
71
+ # to increase past the original budget after expiration. Independent of
72
+ # {#expired?} and {#in_grace?}.
73
+ #
74
+ # @return [Float] seconds elapsed since creation
75
+ def elapsed
76
+ now - @started_at
77
+ end
78
+
68
79
  # Return the remaining time in the grace period.
69
80
  #
70
81
  # @return [Float] seconds remaining in grace period (0.0 if no grace period or grace expired)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module TimeoutKit
5
- VERSION = '0.2.1'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-timeout_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-31 00:00:00.000000000 Z
11
+ date: 2026-04-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A cooperative timeout library providing deadline and timeout patterns
14
14
  that avoid Thread.raise, with nested deadline support, grace periods, callbacks,
@@ -25,11 +25,11 @@ files:
25
25
  - lib/philiprehberger/timeout_kit.rb
26
26
  - lib/philiprehberger/timeout_kit/deadline.rb
27
27
  - lib/philiprehberger/timeout_kit/version.rb
28
- homepage: https://github.com/philiprehberger/rb-timeout-kit
28
+ homepage: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-timeout_kit
29
29
  licenses:
30
30
  - MIT
31
31
  metadata:
32
- homepage_uri: https://github.com/philiprehberger/rb-timeout-kit
32
+ homepage_uri: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-timeout_kit
33
33
  source_code_uri: https://github.com/philiprehberger/rb-timeout-kit
34
34
  changelog_uri: https://github.com/philiprehberger/rb-timeout-kit/blob/main/CHANGELOG.md
35
35
  bug_tracker_uri: https://github.com/philiprehberger/rb-timeout-kit/issues