async 2.30.0 → 2.32.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
- checksums.yaml.gz.sig +0 -0
- data/lib/async/deadline.rb +70 -0
- data/lib/async/priority_queue.rb +4 -1
- data/lib/async/queue.rb +5 -0
- data/lib/async/version.rb +1 -1
- data/readme.md +8 -16
- data/releases.md +8 -0
- data.tar.gz.sig +0 -0
- metadata +2 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a816b65e2cdf3f1f9ee99d421b32f13ed00c858bfa2b1ff0f814cf33c9dd470
|
4
|
+
data.tar.gz: 85dc9dfad110e4ae2f0d4db45db9b1f941b797891f945da1caaa302df233f813
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6cf114ad81e9eb511504ed44b719f9838ad84623fea14aab43acd531a9d8493b92eb0a24a49bb410670c0be82c8de5617280f39e984f1d9477c4828d96d2fc5
|
7
|
+
data.tar.gz: 2acb3e1516b2670a57cb717713d882f9d75807864924bf7aa691aa82cd5406a2b273c7aa813a30037a3dabce338095eb7faa5efff8f5f5b56290a07b3b0927b5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2025, by Samuel Williams.
|
5
|
+
|
6
|
+
require_relative "clock"
|
7
|
+
|
8
|
+
# @namespace
|
9
|
+
module Async
|
10
|
+
# Represents a deadline timeout with decrementing remaining time.
|
11
|
+
# Includes an efficient representation for zero (non-blocking) timeouts.
|
12
|
+
# @public Since *Async v2.31*.
|
13
|
+
class Deadline
|
14
|
+
# Singleton module for immediate timeouts (zero or negative).
|
15
|
+
# Avoids object allocation for fast path (non-blocking) timeouts.
|
16
|
+
module Zero
|
17
|
+
# Check if the deadline has expired.
|
18
|
+
# @returns [Boolean] Always returns true since zero timeouts are immediately expired.
|
19
|
+
def self.expired?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
# Get the remaining time.
|
24
|
+
# @returns [Integer] Always returns 0 since zero timeouts have no remaining time.
|
25
|
+
def self.remaining
|
26
|
+
0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Create a deadline for the given timeout.
|
31
|
+
# @parameter timeout [Numeric | Nil] The timeout duration, or nil for no timeout.
|
32
|
+
# @returns [Deadline | Nil] A deadline instance, Zero singleton, or nil.
|
33
|
+
def self.start(timeout)
|
34
|
+
if timeout.nil?
|
35
|
+
nil
|
36
|
+
elsif timeout <= 0
|
37
|
+
Zero
|
38
|
+
else
|
39
|
+
self.new(timeout)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Create a new deadline with the specified remaining time.
|
44
|
+
# @parameter remaining [Numeric] The initial remaining time.
|
45
|
+
def initialize(remaining)
|
46
|
+
@remaining = remaining
|
47
|
+
@start = Clock.now
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get the remaining time, updating internal state.
|
51
|
+
# Each call to this method advances the internal clock and reduces
|
52
|
+
# the remaining time by the elapsed duration since the last call.
|
53
|
+
# @returns [Numeric] The remaining time (may be negative if expired).
|
54
|
+
def remaining
|
55
|
+
now = Clock.now
|
56
|
+
delta = now - @start
|
57
|
+
@start = now
|
58
|
+
|
59
|
+
@remaining -= delta
|
60
|
+
|
61
|
+
return @remaining
|
62
|
+
end
|
63
|
+
|
64
|
+
# Check if the deadline has expired.
|
65
|
+
# @returns [Boolean] True if no time remains.
|
66
|
+
def expired?
|
67
|
+
self.remaining <= 0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/async/priority_queue.rb
CHANGED
@@ -102,12 +102,15 @@ module Async
|
|
102
102
|
end
|
103
103
|
|
104
104
|
# @returns [Integer] The number of fibers waiting to dequeue.
|
105
|
-
def
|
105
|
+
def waiting_count
|
106
106
|
@mutex.synchronize do
|
107
107
|
@waiting.size
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
+
# @deprecated Use {#waiting_count} instead.
|
112
|
+
alias waiting waiting_count
|
113
|
+
|
111
114
|
# Add an item to the queue.
|
112
115
|
#
|
113
116
|
# @parameter item [Object] The item to add to the queue.
|
data/lib/async/queue.rb
CHANGED
data/lib/async/version.rb
CHANGED
data/readme.md
CHANGED
@@ -35,6 +35,14 @@ Please see the [project documentation](https://socketry.github.io/async/) for mo
|
|
35
35
|
|
36
36
|
Please see the [project releases](https://socketry.github.io/async/releases/index) for all releases.
|
37
37
|
|
38
|
+
### v2.32.0
|
39
|
+
|
40
|
+
- Introduce `Queue#waiting_count` and `PriorityQueue#waiting_count`. Generally for statistics/testing purposes only.
|
41
|
+
|
42
|
+
### v2.31.0
|
43
|
+
|
44
|
+
- Introduce `Async::Deadline` for precise timeout management in compound operations.
|
45
|
+
|
38
46
|
### v2.30.0
|
39
47
|
|
40
48
|
- Add timeout support to `Async::Queue#dequeue` and `Async::Queue#pop` methods.
|
@@ -76,22 +84,6 @@ This release introduces thread-safety as a core concept of Async. Many core clas
|
|
76
84
|
|
77
85
|
- Updated documentation and agent context.
|
78
86
|
|
79
|
-
### v2.27.0
|
80
|
-
|
81
|
-
- `Async::Task#stop` supports an optional `cause:` argument (that defaults to `$!`), which allows you to specify the cause (exception) for stopping the task.
|
82
|
-
- Add thread-safety agent context.
|
83
|
-
|
84
|
-
### v2.26.0
|
85
|
-
|
86
|
-
- `Async::Notification#signal` now returns `true` if a task was signaled, `false` otherwise, providing better feedback for notification operations.
|
87
|
-
- `require "async/limited_queue"` is required to use `Async::LimitedQueue` without a deprecation warning. `Async::LimitedQueue` is not deprecated, but it's usage via `async/queue` is deprecated.
|
88
|
-
- `Async::Task#sleep` is deprecated with no replacement.
|
89
|
-
- `Async::Task.yield` is deprecated with no replacement.
|
90
|
-
- `Async::Scheduler#async` is deprecated, use `Async{}`, `Sync{}` or `Async::Task#async` instead.
|
91
|
-
- Agent context is now available, via the [`agent-context` gem](https://github.com/ioquatix/agent-context).
|
92
|
-
- [`Async::Barrier` Improvements](https://socketry.github.io/async/releases/index#async::barrier-improvements)
|
93
|
-
- [Introduce `Async::Queue#close`](https://socketry.github.io/async/releases/index#introduce-async::queue#close)
|
94
|
-
|
95
87
|
## See Also
|
96
88
|
|
97
89
|
- [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client/server.
|
data/releases.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Releases
|
2
2
|
|
3
|
+
## v2.32.0
|
4
|
+
|
5
|
+
- Introduce `Queue#waiting_count` and `PriorityQueue#waiting_count`. Generally for statistics/testing purposes only.
|
6
|
+
|
7
|
+
## v2.31.0
|
8
|
+
|
9
|
+
- Introduce `Async::Deadline` for precise timeout management in compound operations.
|
10
|
+
|
3
11
|
## v2.30.0
|
4
12
|
|
5
13
|
- Add timeout support to `Async::Queue#dequeue` and `Async::Queue#pop` methods.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.32.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/async/condition.md
|
160
160
|
- lib/async/condition.rb
|
161
161
|
- lib/async/console.rb
|
162
|
+
- lib/async/deadline.rb
|
162
163
|
- lib/async/idler.rb
|
163
164
|
- lib/async/limited_queue.rb
|
164
165
|
- lib/async/list.rb
|
metadata.gz.sig
CHANGED
Binary file
|