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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec9246d9b39f427c0ce91bc4d9538808c0721f391dd29cef5f0a5cf2856a7328
4
- data.tar.gz: 2666f26808cc8401f430c18a5ff47199343ea712c96915bd9325a289de817e93
3
+ metadata.gz: 311898f67ba8c2701c3edcebe315120d09f5b445d5bc32b7c31719d4973f9b7c
4
+ data.tar.gz: d94e9ce7d8da1bb16017c77ee562b87fe8492f5ea60467042a97aa20f4c33493
5
5
  SHA512:
6
- metadata.gz: 130265b9d6ba0d8bc97441e8412732dd7118bf1727712288837ee176d38fbb56aea27534eb235341034d8083ac13f28b2898e98da82767d80f3fda01fbaecb44
7
- data.tar.gz: 77b2eebd91c6a8f0572ecdfc16b6e8bfb902b7d643e4210af9cdd311f074967338e2ddb17eaa520ddeca3d731d72e9799bc856775014f8bb6b039317852d9a31
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
@@ -374,7 +374,10 @@ module ACP
374
374
  listener = @listen_worker
375
375
  return if listener.nil? || Wait.current?(listener)
376
376
 
377
- Wait.stop(listener) unless Wait.join(listener, @worker_grace)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ACP
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
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
- if timeout.nil?
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
- if timeout.nil?
152
- @promise.wait
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acp_sdk_async
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nutsoriginal