async 2.6.4 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d54225f46397da0fca5df7594cce6d324448f5232437bd280427bac01cdfc611
4
- data.tar.gz: d83c10b361eb4b86891e5779dfd2b434d2235a9f381384faf10399da40ef1120
3
+ metadata.gz: 53de22a28c0c092ca81a83cb13c3ffba282d837c3eaab45fac9c8b130e0483a7
4
+ data.tar.gz: 647c8709231ffd1c24d1e6d166978ffe5b7b0ed3da17054dd8c43f131a8b29f5
5
5
  SHA512:
6
- metadata.gz: 8dc3b8d9c4e84139b0a0b3e4293c7a9057fea467374a30a8ed3290b48ac7d623f04c9c00013ffe8f2b8cedcd48b277da173c59985f78a09c62cd845168a1152e
7
- data.tar.gz: 5cc169eb3b18e594474c3bccf957fdaa661322fa4715b2b0a9d025162d3c54a44e6a464b98f9dc157ad2cdf75a3c2a2369ce959066827b46f6ada37572d8e455
6
+ metadata.gz: b38fe4b6304d66e7911f392c15334a0e3fadd4751a593fbcfcc4aa31726d02d7482888f0d038568dee034647cba7453a50916aecb1d40111ee7a3d1d76c555ba
7
+ data.tar.gz: 4b48c52dc39f10835f36e84d25b45ab5b6d89f213c232fd8f791e0c1d318901eb1826a5c57fca8daa95b8ba32f6130e02f022986c40bdfc194aab8506b47a5bb
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/async/node.rb CHANGED
@@ -123,10 +123,6 @@ module Async
123
123
  end
124
124
  end
125
125
 
126
- def annotation
127
- @annotation
128
- end
129
-
130
126
  def description
131
127
  @object_name ||= "#{self.class}:#{format '%#018x', object_id}#{@transient ? ' transient' : nil}"
132
128
 
@@ -165,29 +165,66 @@ module Async
165
165
  ::Resolv.getaddresses(hostname)
166
166
  end
167
167
 
168
+
169
+ if IO.method_defined?(:timeout)
170
+ private def get_timeout(io)
171
+ io.timeout
172
+ end
173
+ else
174
+ private def get_timeout(io)
175
+ nil
176
+ end
177
+ end
178
+
168
179
  # @asynchronous May be non-blocking..
169
180
  def io_wait(io, events, timeout = nil)
170
181
  fiber = Fiber.current
171
182
 
172
183
  if timeout
184
+ # If an explicit timeout is specified, we expect that the user will handle it themselves:
173
185
  timer = @timers.after(timeout) do
174
186
  fiber.transfer
175
187
  end
188
+ elsif timeout = get_timeout(io)
189
+ # Otherwise, if we default to the io's timeout, we raise an exception:
190
+ timer = @timers.after(timeout) do
191
+ fiber.raise(::IO::TimeoutError, "Timeout while waiting for IO to become ready!")
192
+ end
176
193
  end
177
194
 
178
195
  return @selector.io_wait(fiber, io, events)
179
196
  ensure
180
197
  timer&.cancel
181
198
  end
182
-
199
+
183
200
  if ::IO::Event::Support.buffer?
184
201
  def io_read(io, buffer, length, offset = 0)
185
- @selector.io_read(Fiber.current, io, buffer, length, offset)
202
+ fiber = Fiber.current
203
+
204
+ if timeout = get_timeout(io)
205
+ timer = @timers.after(timeout) do
206
+ fiber.raise(::IO::TimeoutError, "execution expired")
207
+ end
208
+ end
209
+
210
+ @selector.io_read(fiber, io, buffer, length, offset)
211
+ ensure
212
+ timer&.cancel
186
213
  end
187
214
 
188
215
  if RUBY_ENGINE != "ruby" || RUBY_VERSION >= "3.3.0"
189
216
  def io_write(io, buffer, length, offset = 0)
190
- @selector.io_write(Fiber.current, io, buffer, length, offset)
217
+ fiber = Fiber.current
218
+
219
+ if timeout = get_timeout(io)
220
+ timer = @timers.after(timeout) do
221
+ fiber.raise(::IO::TimeoutError, "execution expired")
222
+ end
223
+ end
224
+
225
+ @selector.io_write(fiber, io, buffer, length, offset)
226
+ ensure
227
+ timer&.cancel
191
228
  end
192
229
  end
193
230
  end
data/lib/async/task.rb CHANGED
@@ -175,7 +175,7 @@ module Async
175
175
  return task
176
176
  end
177
177
 
178
- # Retrieve the current result of the task. Will cause the caller to wait until result is available. If the result was an exception, raise that exception.
178
+ # Retrieve the current result of the task. Will cause the caller to wait until result is available. If the task resulted in an unhandled error (derived from `StandardError`), this will be raised. If the task was stopped, this will return `nil`.
179
179
  #
180
180
  # Conceptually speaking, waiting on a task should return a result, and if it throws an exception, this is certainly an exceptional case that should represent a failure in your program, not an expected outcome. In other words, you should not design your programs to expect exceptions from `#wait` as a normal flow control, and prefer to catch known exceptions within the task itself and return a result that captures the intention of the failure, e.g. a `TimeoutError` might simply return `nil` or `false` to indicate that the operation did not generate a valid result (as a timeout was an expected outcome of the internal operation in this case).
181
181
  #
data/lib/async/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2023, by Samuel Williams.
5
5
 
6
6
  module Async
7
- VERSION = "2.6.4"
7
+ VERSION = "2.7.0"
8
8
  end
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.6.4
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -58,7 +58,7 @@ cert_chain:
58
58
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
59
59
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
60
60
  -----END CERTIFICATE-----
61
- date: 2023-08-25 00:00:00.000000000 Z
61
+ date: 2024-01-02 00:00:00.000000000 Z
62
62
  dependencies:
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: console
@@ -266,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
266
  - !ruby/object:Gem::Version
267
267
  version: '0'
268
268
  requirements: []
269
- rubygems_version: 3.5.0.dev
269
+ rubygems_version: 3.4.22
270
270
  signing_key:
271
271
  specification_version: 4
272
272
  summary: A concurrency framework for Ruby.
metadata.gz.sig CHANGED
Binary file