async 2.29.1 → 2.30.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/priority_queue.rb +21 -8
- data/lib/async/queue.rb +8 -4
- data/lib/async/version.rb +1 -1
- data/readme.md +7 -6
- data/releases.md +7 -0
- data.tar.gz.sig +0 -0
- metadata +2 -2
- 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: 1423e2d1cc2a1e1aec71d5e70640a0b8c8069d6a2b2af9da63f7bed3d0c9d548
|
4
|
+
data.tar.gz: 2529e362cd8141d9fa0d8a6ea29fd0d74298630cdd8d4034633c20365a2c5491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3455b22a4ea6a6e438e1da05ab9c4f5e7cf4d7f8f465138814c71743b2a6d7c1b1525cc3bb13b065b0aa67d0a57d5409d23cc101c61bd026c6ace345919f0005
|
7
|
+
data.tar.gz: fb21c61222c5067d272f8e5b845fcdef9ce2f99ab831cebf6575e94068b5e22f365569a2b2af1c5ec704b7e1bf53de93ef4c6143c014e5d77f9995908761b975
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/async/priority_queue.rb
CHANGED
@@ -39,8 +39,8 @@ module Async
|
|
39
39
|
condition.signal
|
40
40
|
end
|
41
41
|
|
42
|
-
def wait_for_value(mutex)
|
43
|
-
condition.wait(mutex)
|
42
|
+
def wait_for_value(mutex, timeout = nil)
|
43
|
+
condition.wait(mutex, timeout)
|
44
44
|
return self.value
|
45
45
|
end
|
46
46
|
|
@@ -55,6 +55,8 @@ module Async
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
private_constant :Waiter
|
59
|
+
|
58
60
|
# Create a new priority queue.
|
59
61
|
#
|
60
62
|
# @parameter parent [Interface(:async) | Nil] The parent task to use for async operations.
|
@@ -81,6 +83,11 @@ module Async
|
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
86
|
+
# @returns [Boolean] Whether the queue is closed.
|
87
|
+
def closed?
|
88
|
+
@closed
|
89
|
+
end
|
90
|
+
|
84
91
|
# @attribute [Array] The items in the queue.
|
85
92
|
attr :items
|
86
93
|
|
@@ -153,13 +160,14 @@ module Async
|
|
153
160
|
|
154
161
|
# Remove and return the next item from the queue.
|
155
162
|
#
|
156
|
-
# If the queue is empty, this method will block until an item is available.
|
163
|
+
# If the queue is empty, this method will block until an item is available or timeout expires.
|
157
164
|
# Fibers are served in priority order, with higher priority fibers receiving
|
158
165
|
# items first.
|
159
166
|
#
|
160
167
|
# @parameter priority [Numeric] The priority of this consumer (higher = served first).
|
161
|
-
# @
|
162
|
-
|
168
|
+
# @parameter timeout [Numeric, nil] Maximum time to wait for an item. If nil, waits indefinitely. If 0, returns immediately.
|
169
|
+
# @returns [Object, nil] The next item in the queue, or nil if timeout expires.
|
170
|
+
def dequeue(priority: 0, timeout: nil)
|
163
171
|
@mutex.synchronize do
|
164
172
|
# If queue is closed and empty, return nil immediately:
|
165
173
|
if @closed && @items.empty?
|
@@ -174,6 +182,9 @@ module Async
|
|
174
182
|
end
|
175
183
|
end
|
176
184
|
|
185
|
+
# Handle immediate timeout (non-blocking)
|
186
|
+
return nil if timeout == 0
|
187
|
+
|
177
188
|
# Need to wait - create our own condition variable and add to waiting queue:
|
178
189
|
sequence = @sequence
|
179
190
|
@sequence += 1
|
@@ -185,7 +196,7 @@ module Async
|
|
185
196
|
@waiting.push(waiter)
|
186
197
|
|
187
198
|
# Wait for our specific condition variable to be signaled:
|
188
|
-
return waiter.wait_for_value(@mutex)
|
199
|
+
return waiter.wait_for_value(@mutex, timeout)
|
189
200
|
ensure
|
190
201
|
waiter&.invalidate!
|
191
202
|
end
|
@@ -195,8 +206,10 @@ module Async
|
|
195
206
|
# Compatibility with {::Queue#pop}.
|
196
207
|
#
|
197
208
|
# @parameter priority [Numeric] The priority of this consumer.
|
198
|
-
|
199
|
-
|
209
|
+
# @parameter timeout [Numeric, nil] Maximum time to wait for an item. If nil, waits indefinitely. If 0, returns immediately.
|
210
|
+
# @returns [Object, nil] The dequeued item, or nil if timeout expires.
|
211
|
+
def pop(priority: 0, timeout: nil)
|
212
|
+
self.dequeue(priority: priority, timeout: timeout)
|
200
213
|
end
|
201
214
|
|
202
215
|
# Process each item in the queue.
|
data/lib/async/queue.rb
CHANGED
@@ -73,13 +73,17 @@ module Async
|
|
73
73
|
end
|
74
74
|
|
75
75
|
# Remove and return the next item from the queue.
|
76
|
-
|
77
|
-
|
76
|
+
# @parameter timeout [Numeric, nil] Maximum time to wait for an item. If nil, waits indefinitely. If 0, returns immediately.
|
77
|
+
# @returns [Object, nil] The dequeued item, or nil if timeout expires.
|
78
|
+
def dequeue(timeout: nil)
|
79
|
+
@delegate.pop(timeout: timeout)
|
78
80
|
end
|
79
81
|
|
80
82
|
# Compatibility with {::Queue#pop}.
|
81
|
-
|
82
|
-
|
83
|
+
# @parameter timeout [Numeric, nil] Maximum time to wait for an item. If nil, waits indefinitely. If 0, returns immediately.
|
84
|
+
# @returns [Object, nil] The dequeued item, or nil if timeout expires.
|
85
|
+
def pop(timeout: nil)
|
86
|
+
@delegate.pop(timeout: timeout)
|
83
87
|
end
|
84
88
|
|
85
89
|
# Process each item in the queue.
|
data/lib/async/version.rb
CHANGED
data/readme.md
CHANGED
@@ -35,6 +35,13 @@ 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.30.0
|
39
|
+
|
40
|
+
- Add timeout support to `Async::Queue#dequeue` and `Async::Queue#pop` methods.
|
41
|
+
- Add timeout support to `Async::PriorityQueue#dequeue` and `Async::PriorityQueue#pop` methods.
|
42
|
+
- Add `closed?` method to `Async::PriorityQueue` for full queue interface compatibility.
|
43
|
+
- Support non-blocking operations using `timeout: 0` parameter.
|
44
|
+
|
38
45
|
### v2.29.0
|
39
46
|
|
40
47
|
This release introduces thread-safety as a core concept of Async. Many core classes now have thread-safe guarantees, allowing them to be used safely across multiple threads.
|
@@ -85,12 +92,6 @@ This release introduces thread-safety as a core concept of Async. Many core clas
|
|
85
92
|
- [`Async::Barrier` Improvements](https://socketry.github.io/async/releases/index#async::barrier-improvements)
|
86
93
|
- [Introduce `Async::Queue#close`](https://socketry.github.io/async/releases/index#introduce-async::queue#close)
|
87
94
|
|
88
|
-
### v2.25.0
|
89
|
-
|
90
|
-
- Added support for `io_select` hook in the fiber scheduler, allowing non-blocking `IO.select` operations. This enables better integration with code that uses `IO.select` for multiplexing IO operations.
|
91
|
-
- [Use `IO::Event::WorkerPool` for Blocking Operations](https://socketry.github.io/async/releases/index#use-io::event::workerpool-for-blocking-operations)
|
92
|
-
- [Better handling of `IO#close` using `fiber_interrupt`](https://socketry.github.io/async/releases/index#better-handling-of-io#close-using-fiber_interrupt)
|
93
|
-
|
94
95
|
## See Also
|
95
96
|
|
96
97
|
- [async-http](https://github.com/socketry/async-http) — Asynchronous HTTP client/server.
|
data/releases.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Releases
|
2
2
|
|
3
|
+
## v2.30.0
|
4
|
+
|
5
|
+
- Add timeout support to `Async::Queue#dequeue` and `Async::Queue#pop` methods.
|
6
|
+
- Add timeout support to `Async::PriorityQueue#dequeue` and `Async::PriorityQueue#pop` methods.
|
7
|
+
- Add `closed?` method to `Async::PriorityQueue` for full queue interface compatibility.
|
8
|
+
- Support non-blocking operations using `timeout: 0` parameter.
|
9
|
+
|
3
10
|
## v2.29.0
|
4
11
|
|
5
12
|
This release introduces thread-safety as a core concept of Async. Many core classes now have thread-safe guarantees, allowing them to be used safely across multiple threads.
|
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.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -209,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
209
|
- !ruby/object:Gem::Version
|
210
210
|
version: '0'
|
211
211
|
requirements: []
|
212
|
-
rubygems_version: 3.
|
212
|
+
rubygems_version: 3.6.9
|
213
213
|
specification_version: 4
|
214
214
|
summary: A concurrency framework for Ruby.
|
215
215
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|