philiprehberger-timeout_kit 0.2.0 → 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 +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +25 -8
- data/lib/philiprehberger/timeout_kit/deadline.rb +12 -1
- data/lib/philiprehberger/timeout_kit/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 80b321def31fd94ffb7e7800f957ed9dcc2037245dfbe90a1213a2bad9e0366d
|
|
4
|
+
data.tar.gz: cdff9dc81339f285c3209a505644d0ed772943d415c9e58dd731a270b8e0b0db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34fa84c7798b419ba9ba807ecd824a5f20f143cd304e4b96874648c8dec0de012461543ab3af08411898f05011c2967a23e5ff8a488acb88f3a83d35d710bc58
|
|
7
|
+
data.tar.gz: 2234c624205be2928d8dc09d5257222116d7983af96f88e4d05c3610baf02e7fceb2a5d80ffc8412375562f522f7e99e93ec0704e7106bb6bf0bbf77193828df
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ 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
|
+
|
|
15
|
+
## [0.2.1] - 2026-03-31
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- Standardize README badges, support section, and license format
|
|
19
|
+
|
|
10
20
|
## [0.2.0] - 2026-03-29
|
|
11
21
|
|
|
12
22
|
### Added
|
data/README.md
CHANGED
|
@@ -2,12 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/philiprehberger/rb-timeout-kit/actions/workflows/ci.yml)
|
|
4
4
|
[](https://rubygems.org/gems/philiprehberger-timeout_kit)
|
|
5
|
-
[](https://github.com/philiprehberger/rb-timeout-kit/releases)
|
|
6
5
|
[](https://github.com/philiprehberger/rb-timeout-kit/commits/main)
|
|
7
|
-
[](LICENSE)
|
|
8
|
-
[](https://github.com/philiprehberger/rb-timeout-kit/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
|
|
9
|
-
[](https://github.com/philiprehberger/rb-timeout-kit/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)
|
|
10
|
-
[](https://github.com/sponsors/philiprehberger)
|
|
11
6
|
|
|
12
7
|
Safe timeout patterns without Thread.raise
|
|
13
8
|
|
|
@@ -54,6 +49,16 @@ Philiprehberger::TimeoutKit.deadline(10) do |d|
|
|
|
54
49
|
end
|
|
55
50
|
```
|
|
56
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
|
+
|
|
57
62
|
### Nested Deadlines
|
|
58
63
|
|
|
59
64
|
```ruby
|
|
@@ -145,6 +150,7 @@ end
|
|
|
145
150
|
| `.current_deadline` | Return the current active deadline or nil |
|
|
146
151
|
| `Deadline#check!` | Raise `DeadlineExceeded` if the deadline has passed (respects grace period) |
|
|
147
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) |
|
|
148
154
|
| `Deadline#expired?` | Whether the primary deadline has passed |
|
|
149
155
|
| `Deadline#name` | The human-readable name for this deadline (nil if not set) |
|
|
150
156
|
| `Deadline#in_grace?` | Whether the deadline is in the grace period |
|
|
@@ -162,10 +168,21 @@ bundle exec rubocop
|
|
|
162
168
|
|
|
163
169
|
## Support
|
|
164
170
|
|
|
165
|
-
If you find this
|
|
171
|
+
If you find this project useful:
|
|
172
|
+
|
|
173
|
+
⭐ [Star the repo](https://github.com/philiprehberger/rb-timeout-kit)
|
|
174
|
+
|
|
175
|
+
🐛 [Report issues](https://github.com/philiprehberger/rb-timeout-kit/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
|
|
176
|
+
|
|
177
|
+
💡 [Suggest features](https://github.com/philiprehberger/rb-timeout-kit/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)
|
|
178
|
+
|
|
179
|
+
❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)
|
|
180
|
+
|
|
181
|
+
🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)
|
|
182
|
+
|
|
183
|
+
💻 [GitHub Profile](https://github.com/philiprehberger)
|
|
166
184
|
|
|
167
|
-
[
|
|
168
|
-
[](https://philiprehberger.com/open-source-packages)
|
|
185
|
+
🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)
|
|
169
186
|
|
|
170
187
|
## License
|
|
171
188
|
|
|
@@ -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
|
-
@
|
|
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)
|
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.
|
|
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-
|
|
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://
|
|
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://
|
|
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
|