philiprehberger-timeout_kit 0.3.0 → 0.4.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: 80b321def31fd94ffb7e7800f957ed9dcc2037245dfbe90a1213a2bad9e0366d
4
- data.tar.gz: cdff9dc81339f285c3209a505644d0ed772943d415c9e58dd731a270b8e0b0db
3
+ metadata.gz: 9dfc9b63782aba549dbc26a8ee6d86dda684966ecdad05feef37e76c76b711ef
4
+ data.tar.gz: 701cb726e36b5fc249ba29e4f21b4c870e4a1f26239b67661ec6e749798876c2
5
5
  SHA512:
6
- metadata.gz: 34fa84c7798b419ba9ba807ecd824a5f20f143cd304e4b96874648c8dec0de012461543ab3af08411898f05011c2967a23e5ff8a488acb88f3a83d35d710bc58
7
- data.tar.gz: 2234c624205be2928d8dc09d5257222116d7983af96f88e4d05c3610baf02e7fceb2a5d80ffc8412375562f522f7e99e93ec0704e7106bb6bf0bbf77193828df
6
+ metadata.gz: 97067f5fb32a46696cc861eacdf1f4f986b4031694affc5a7ee905666cfd240e05323beebd32819c6b5b7cdc220b1f91b29c88e68208a7ff159d44504df86d38
7
+ data.tar.gz: 2da040fd6f4c14d1dff37ae0524bea4d12e65510aa888eed55410c6cf3c0453380c8b0b83da22fecab7d51b1d2f763bdb6401e746461d3b9706212e34baaec37
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2026-05-07
11
+
12
+ ### Added
13
+ - `Deadline#duration` — exposes the original budget passed to `Deadline.new`.
14
+ - `Deadline#progress` — fraction of the budget consumed, useful for progress bars and adaptive cancellation.
15
+
10
16
  ## [0.3.0] - 2026-04-17
11
17
 
12
18
  ### Added
data/README.md CHANGED
@@ -59,6 +59,14 @@ Philiprehberger::TimeoutKit.deadline(10) do |d|
59
59
  end
60
60
  ```
61
61
 
62
+ ### Deadline Progress
63
+
64
+ ```ruby
65
+ deadline = Philiprehberger::TimeoutKit::Deadline.new(10)
66
+ sleep 5
67
+ deadline.progress # => 0.5 (approximately)
68
+ ```
69
+
62
70
  ### Nested Deadlines
63
71
 
64
72
  ```ruby
@@ -151,6 +159,8 @@ end
151
159
  | `Deadline#check!` | Raise `DeadlineExceeded` if the deadline has passed (respects grace period) |
152
160
  | `Deadline#remaining` | Seconds remaining until the primary deadline (negative during grace) |
153
161
  | `Deadline#elapsed` | Seconds elapsed since the deadline was created (continues past the budget after expiration) |
162
+ | `Deadline#duration` | The original budget passed to `Deadline.new` (Float) |
163
+ | `Deadline#progress` | Fraction of the budget that has elapsed (`elapsed / duration`); exceeds 1.0 after expiry |
154
164
  | `Deadline#expired?` | Whether the primary deadline has passed |
155
165
  | `Deadline#name` | The human-readable name for this deadline (nil if not set) |
156
166
  | `Deadline#in_grace?` | Whether the deadline is in the grace period |
@@ -13,6 +13,11 @@ module Philiprehberger
13
13
  # @return [String, nil] the human-readable name for this deadline
14
14
  attr_reader :name
15
15
 
16
+ # The original budget passed to {.new} as +seconds+.
17
+ #
18
+ # @return [Float] the original deadline duration in seconds
19
+ attr_reader :duration
20
+
16
21
  # Create a new deadline.
17
22
  #
18
23
  # @param seconds [Numeric] the number of seconds until the deadline expires
@@ -21,6 +26,7 @@ module Philiprehberger
21
26
  # @param on_expire [Proc, nil] optional callback that fires once when expiry is detected
22
27
  def initialize(seconds, name: nil, grace: nil, on_expire: nil)
23
28
  @started_at = now
29
+ @duration = seconds.to_f
24
30
  @expires_at = @started_at + seconds
25
31
  @name = name
26
32
  @grace_seconds = grace
@@ -76,6 +82,17 @@ module Philiprehberger
76
82
  now - @started_at
77
83
  end
78
84
 
85
+ # Fraction of the original budget that has elapsed (0.0..1.0+).
86
+ # Exceeds 1.0 once the primary deadline has expired (and during grace period).
87
+ # Returns 1.0 if the original budget is zero.
88
+ #
89
+ # @return [Float] elapsed / duration
90
+ def progress
91
+ return 1.0 if @duration.zero?
92
+
93
+ elapsed / @duration
94
+ end
95
+
79
96
  # Return the remaining time in the grace period.
80
97
  #
81
98
  # @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.3.0'
5
+ VERSION = '0.4.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.3.0
4
+ version: 0.4.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-04-18 00:00:00.000000000 Z
11
+ date: 2026-05-07 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,