acp_sdk_async 0.3.0 → 0.3.1
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 +16 -0
- data/lib/acp/connection.rb +4 -1
- data/lib/acp/version.rb +1 -1
- data/lib/acp/wait.rb +20 -12
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 311898f67ba8c2701c3edcebe315120d09f5b445d5bc32b7c31719d4973f9b7c
|
|
4
|
+
data.tar.gz: d94e9ce7d8da1bb16017c77ee562b87fe8492f5ea60467042a97aa20f4c33493
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c65a6d278fd08ce6e9fb08cbda659c1eb3fd5805a43f345514ef6cb516534a76c89acb1aa8fc1d99d2fcde0ee92453db1268144884dd87097ba7b1892857f3a
|
|
7
|
+
data.tar.gz: 014db843ff5839284074e89f56acdb18eacdc8de8387d678892b345b56bd1392fe4232637fb4506623d0c8b2f02e37347114859de8ea44db7381345e3a30ed8a
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.3.1]
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Support `async` down to 2.32 (the gemspec minimum):
|
|
10
|
+
`Promise#wait(timeout:)` only exists on newer releases, so timed
|
|
11
|
+
waits now fall back to `with_timeout` around a blocking wait.
|
|
12
|
+
- Faster connection close: stop the listen task before joining it
|
|
13
|
+
(it never exits on its own while the peer is alive). Full suite
|
|
14
|
+
went from ~35s down to ~6s.
|
|
15
|
+
|
|
16
|
+
### Compatibility
|
|
17
|
+
|
|
18
|
+
- Verified: full suite (189 tests) green on Ruby 3.2, 3.3, 3.4 and 4.0,
|
|
19
|
+
with `async` 2.32, 2.36, 2.37, 2.38 and 2.45.
|
|
20
|
+
|
|
5
21
|
## [0.3.0]
|
|
6
22
|
|
|
7
23
|
### Added
|
data/lib/acp/connection.rb
CHANGED
|
@@ -374,7 +374,10 @@ module ACP
|
|
|
374
374
|
listener = @listen_worker
|
|
375
375
|
return if listener.nil? || Wait.current?(listener)
|
|
376
376
|
|
|
377
|
-
|
|
377
|
+
# Stop first, then join: the listener never finishes on its own while
|
|
378
|
+
# the peer is alive, so joining first would always burn the full grace.
|
|
379
|
+
Wait.stop(listener)
|
|
380
|
+
Wait.join(listener, @worker_grace)
|
|
378
381
|
end
|
|
379
382
|
end
|
|
380
383
|
end
|
data/lib/acp/version.rb
CHANGED
data/lib/acp/wait.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "async"
|
|
4
4
|
require "async/promise"
|
|
5
5
|
require "logger"
|
|
6
|
+
require "timeout"
|
|
6
7
|
require_relative "exceptions"
|
|
7
8
|
|
|
8
9
|
module ACP
|
|
@@ -102,6 +103,21 @@ module ACP
|
|
|
102
103
|
worker.finished? || !alive?(worker)
|
|
103
104
|
end
|
|
104
105
|
|
|
106
|
+
# Promise#wait(timeout:) only exists on newer async releases.
|
|
107
|
+
# Older ones get the same semantics via with_timeout around a
|
|
108
|
+
# blocking wait; outside a reactor fall back to stdlib Timeout.
|
|
109
|
+
def self.wait_promise(promise, timeout)
|
|
110
|
+
return promise.wait if timeout.nil?
|
|
111
|
+
|
|
112
|
+
if promise.method(:wait).parameters.any? { |type, _| %i[key keyrest].include?(type) }
|
|
113
|
+
promise.wait(timeout: timeout)
|
|
114
|
+
elsif async?
|
|
115
|
+
::Async::Task.current.with_timeout(timeout) { promise.wait }
|
|
116
|
+
else
|
|
117
|
+
::Timeout.timeout(timeout) { promise.wait }
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
105
121
|
class Latch
|
|
106
122
|
def initialize
|
|
107
123
|
@promise = ::Async::Promise.new
|
|
@@ -116,13 +132,9 @@ module ACP
|
|
|
116
132
|
end
|
|
117
133
|
|
|
118
134
|
def wait(timeout = nil)
|
|
119
|
-
|
|
120
|
-
@promise.wait
|
|
121
|
-
else
|
|
122
|
-
@promise.wait(timeout: timeout)
|
|
123
|
-
end
|
|
135
|
+
Wait.wait_promise(@promise, timeout)
|
|
124
136
|
true
|
|
125
|
-
rescue ::Async::TimeoutError
|
|
137
|
+
rescue ::Async::TimeoutError, ::Timeout::Error
|
|
126
138
|
false
|
|
127
139
|
end
|
|
128
140
|
end
|
|
@@ -148,12 +160,8 @@ module ACP
|
|
|
148
160
|
end
|
|
149
161
|
|
|
150
162
|
def wait(timeout = nil)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
else
|
|
154
|
-
@promise.wait(timeout: timeout)
|
|
155
|
-
end
|
|
156
|
-
rescue ::Async::TimeoutError
|
|
163
|
+
Wait.wait_promise(@promise, timeout)
|
|
164
|
+
rescue ::Async::TimeoutError, ::Timeout::Error
|
|
157
165
|
raise TimeoutError, "Timed out after #{timeout}s"
|
|
158
166
|
end
|
|
159
167
|
end
|