async 2.0.0 → 2.0.3

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: 6e5f7f4cbc1cfc595409b58cfc0b74e2a2767837fc40bae5e1a1b60e7dcd3384
4
- data.tar.gz: 4eeb27d8248bc7993cf7758e41c8ffee3a54141d7c521e2a2805bbc8e8be3edd
3
+ metadata.gz: 4e8368066a9018b0f3c21ee8c4387cebc233250a4d01697a06051aceee67924b
4
+ data.tar.gz: 80dbe862ee18e562c20acd59c428e2d9ef9b17097229621c3d22cdafb2705f5e
5
5
  SHA512:
6
- metadata.gz: d0b59a751dd4ea8cd7f2a83ad76fbf4dcff30ca11629d2e7f6ba18e017cf5de06880c1a6b19a3297967793e80394e10f8873ed24aa278d2019b11eb90a002394
7
- data.tar.gz: 1c23c709f983bc14ba1477b41b3ca7533275eb3464928c7d4d564e897fc2fb893617cde7bb6d1e90d050db9bbc1d1d2ed71c87da02e61cd559f0afef363fc567
6
+ metadata.gz: b4a0786f488161edbf99e3933f983938561d79f9d9f94902dcb4c79120ffe12c2743cc69aad1d258bbe1aae5bab10a90007ae0065e22576885377b11e423df1b
7
+ data.tar.gz: 224c584693a4a714d7cd9e10062c7975c7fbd8b785f84e46e44151acebb5bc74b136bb9eec5d1d828c5fbfc7cd853e29fb63cd5de3ae7afc8c232e2f9e0af722
checksums.yaml.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ <ռ�oݲ[�B��p�����&���������68����|�=4��o+>�Ž��`�W������P;�J����'�hA/=�x�
2
+ rre�N%�­ x��A�<��a5&�[�_��z���vݸi�u:)l�����NgN�� /� ��m�̖�0����@u�T_V�� �p���Ck볅�
3
+ �U6�]w$�!U?� �DC�Q虶��}b����/��A���IJB���aʠlXIj�h�Lz�S�ѠԀ���1[G�:�6�Ke�Zn�gH�ڶ���� @����gV��!u�۵���
data/lib/async/barrier.rb CHANGED
@@ -69,8 +69,11 @@ module Async
69
69
  begin
70
70
  task.wait
71
71
  ensure
72
- # Remove the task from the waiting list if it's finished:
73
- @tasks.shift if @tasks.first == task
72
+ # We don't know for sure that the exception was due to the task completion.
73
+ unless task.running?
74
+ # Remove the task from the waiting list if it's finished:
75
+ @tasks.shift if @tasks.first == task
76
+ end
74
77
  end
75
78
  end
76
79
  end
data/lib/async/node.rb CHANGED
@@ -218,7 +218,7 @@ module Async
218
218
  end
219
219
 
220
220
  def description
221
- @object_name ||= "#{self.class}:0x#{object_id.to_s(16)}#{@transient ? ' transient' : nil}"
221
+ @object_name ||= "#{self.class}:#{format '%#018x', object_id}#{@transient ? ' transient' : nil}"
222
222
 
223
223
  if @annotation
224
224
  "#{@object_name} #{@annotation}"
data/lib/async/queue.rb CHANGED
@@ -43,14 +43,16 @@ module Async
43
43
  @items.empty?
44
44
  end
45
45
 
46
- def enqueue(item)
47
- @items.push(item)
46
+ def <<(item)
47
+ @items << item
48
48
 
49
49
  self.signal unless self.empty?
50
50
  end
51
51
 
52
- def <<(item)
53
- enqueue(item)
52
+ def enqueue(*items)
53
+ @items.concat(items)
54
+
55
+ self.signal unless self.empty?
54
56
  end
55
57
 
56
58
  def dequeue
@@ -91,7 +93,7 @@ module Async
91
93
  @items.size >= @limit
92
94
  end
93
95
 
94
- def enqueue item
96
+ def <<(item)
95
97
  while limited?
96
98
  @full.wait
97
99
  end
@@ -99,6 +101,19 @@ module Async
99
101
  super
100
102
  end
101
103
 
104
+ def enqueue *items
105
+ while !items.empty?
106
+ while limited?
107
+ @full.wait
108
+ end
109
+
110
+ available = @limit - @items.size
111
+ @items.concat(items.shift(available))
112
+
113
+ self.signal unless self.empty?
114
+ end
115
+ end
116
+
102
117
  def dequeue
103
118
  item = super
104
119
 
data/lib/async/reactor.rb CHANGED
@@ -34,7 +34,6 @@ module Async
34
34
  Fiber.set_scheduler(self)
35
35
  end
36
36
 
37
- alias with_timeout timeout_after
38
37
  public :sleep
39
38
  end
40
39
  end
@@ -102,11 +102,7 @@ module Async
102
102
  end
103
103
 
104
104
  def resume(fiber, *arguments)
105
- if Fiber.scheduler
106
- @selector.resume(fiber, *arguments)
107
- else
108
- @selector.push(fiber)
109
- end
105
+ @selector.resume(fiber, *arguments)
110
106
  end
111
107
 
112
108
  # Invoked when a fiber tries to perform a blocking operation which cannot continue. A corresponding call {unblock} must be performed to allow this fiber to continue.
@@ -282,10 +278,10 @@ module Async
282
278
 
283
279
  # Invoke the block, but after the specified timeout, raise {TimeoutError} in any currenly blocking operation. If the block runs to completion before the timeout occurs or there are no non-blocking operations after the timeout expires, the code will complete without any exception.
284
280
  # @parameter duration [Numeric] The time in seconds, in which the task should complete.
285
- def timeout_after(timeout, exception = TimeoutError, message = "execution expired", &block)
281
+ def with_timeout(duration, exception = TimeoutError, message = "execution expired", &block)
286
282
  fiber = Fiber.current
287
283
 
288
- timer = @timers.after(timeout) do
284
+ timer = @timers.after(duration) do
289
285
  if fiber.alive?
290
286
  fiber.raise(exception, message)
291
287
  end
@@ -295,5 +291,11 @@ module Async
295
291
  ensure
296
292
  timer.cancel if timer
297
293
  end
294
+
295
+ def timeout_after(duration, exception, message, &block)
296
+ with_timeout(duration, exception, message) do |timer|
297
+ yield duration
298
+ end
299
+ end
298
300
  end
299
301
  end
data/lib/async/task.rb CHANGED
@@ -92,9 +92,9 @@ module Async
92
92
  super
93
93
  end
94
94
 
95
- # @deprecated Replaced by {Scheduler#timeout_after}.
96
- def with_timeout(timeout, exception = TimeoutError, message = "execution expired", &block)
97
- Fiber.scheduler.timeout_after(timeout, exception, message, &block)
95
+ # Execute the given block of code, raising the specified exception if it exceeds the given duration during a non-blocking operation.
96
+ def with_timeout(duration, exception = TimeoutError, message = "execution expired", &block)
97
+ Fiber.scheduler.with_timeout(duration, exception, message, &block)
98
98
  end
99
99
 
100
100
  # Yield back to the reactor and allow other fibers to execute.
@@ -163,7 +163,7 @@ module Async
163
163
  if self.running?
164
164
  if self.current?
165
165
  if later
166
- Fiber.scheduler.push Stop::Later.new(self)
166
+ Fiber.scheduler.push(Stop::Later.new(self))
167
167
  else
168
168
  raise Stop, "Stopping current task!"
169
169
  end
@@ -171,7 +171,7 @@ module Async
171
171
  begin
172
172
  Fiber.scheduler.raise(@fiber, Stop)
173
173
  rescue FiberError
174
- Fiber.scheduler.push Stop::Later.new(self)
174
+ Fiber.scheduler.push(Stop::Later.new(self))
175
175
  end
176
176
  end
177
177
  else
@@ -206,17 +206,13 @@ module Async
206
206
  # Whether we can remove this node from the reactor graph.
207
207
  # @returns [Boolean]
208
208
  def finished?
209
- super && @status != :running
209
+ super && @fiber.nil?
210
210
  end
211
211
 
212
212
  def failed?
213
213
  @status == :failed
214
214
  end
215
215
 
216
- def stopping?
217
- @status == :stopping
218
- end
219
-
220
216
  def stopped?
221
217
  @status == :stopped
222
218
  end
@@ -228,18 +224,19 @@ module Async
228
224
  private
229
225
 
230
226
  # This is a very tricky aspect of tasks to get right. I've modelled it after `Thread` but it's slightly different in that the exception can propagate back up through the reactor. If the user writes code which raises an exception, that exception should always be visible, i.e. cause a failure. If it's not visible, such code fails silently and can be very difficult to debug.
231
- # As an explcit choice, the user can start a task which doesn't propagate exceptions. This only applies to `StandardError` and derived tasks. This allows tasks to internally capture their error state which is raised when invoking `Task#result` similar to how `Thread#join` works. This mode makes {ruby Async::Task} behave more like a promise, and you would need to ensure that someone calls `Task#result` otherwise you might miss important errors.
232
- def fail!(exception = nil, propagate = true)
227
+ def fail!(exception = false, propagate = true)
233
228
  @status = :failed
234
229
  @result = exception
235
230
 
236
- if propagate
237
- raise
238
- elsif @finished.nil?
239
- # If no one has called wait, we log this as an error:
240
- Console.logger.error(self) {$!}
241
- else
242
- Console.logger.debug(self) {$!}
231
+ if exception
232
+ if propagate
233
+ raise exception
234
+ elsif @finished.nil?
235
+ # If no one has called wait, we log this as a warning:
236
+ Console.logger.warn(self, "Task may have ended with unhandled exception.", exception)
237
+ else
238
+ Console.logger.debug(self, exception)
239
+ end
243
240
  end
244
241
  end
245
242
 
data/lib/async/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Async
24
- VERSION = "2.0.0"
24
+ VERSION = "2.0.3"
25
25
  end
data/lib/async/wrapper.rb CHANGED
@@ -64,7 +64,7 @@ module Async
64
64
  # Wait fo the io to become either readable or writable.
65
65
  # @parameter duration [Float] timeout after the given duration if not `nil`.
66
66
  def wait_any(timeout = @timeout)
67
- @io.wait_any(timeout) or raise TimeoutError
67
+ @io.to_io.wait(::IO::READABLE|::IO::WRITABLE|::IO::PRIORITY, timeout) or raise TimeoutError
68
68
  end
69
69
 
70
70
  # Close the io and monitor.
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Bruno Sutic
9
+ - Devin Christensen
10
+ - Jeremy Jung
11
+ - Kent Gruber
12
+ - jeremyjung
13
+ - Brian Morearty
14
+ - Jiang Jinyang
15
+ - Julien Portalier
16
+ - Olle Jonsson
17
+ - Patrik Wenger
18
+ - Ryan Musgrave
19
+ - Salim Semaoune
20
+ - Shannon Skipper
21
+ - Sokolov Yura aka funny_falcon
22
+ - Stefan Wrobel
23
+ - jasl
24
+ - muryoimpl
8
25
  autorequire:
9
26
  bindir: bin
10
- cert_chain: []
11
- date: 2021-12-25 00:00:00.000000000 Z
27
+ cert_chain:
28
+ - |
29
+ -----BEGIN CERTIFICATE-----
30
+ MIIEhDCCAuygAwIBAgIBATANBgkqhkiG9w0BAQsFADA3MTUwMwYDVQQDDCxzYW11
31
+ ZWwud2lsbGlhbXMvREM9b3Jpb250cmFuc2Zlci9EQz1jby9EQz1uejAeFw0yMTA4
32
+ MTYwNjMzNDRaFw0yMjA4MTYwNjMzNDRaMDcxNTAzBgNVBAMMLHNhbXVlbC53aWxs
33
+ aWFtcy9EQz1vcmlv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mGLh4o4uJp7w
49
+ x9KCFaR8Lvn/r0oJWJOqb/DMAYI83YeN2Dlt3jpwrsmsONrtC5S3gOUle5afSGos
50
+ bYt5ocnEpKSomR9ZtnCGljds/aeO1Xgpn2r9HHcjwnH346iNrnHmMlC7BtHUFPDg
51
+ Ts92S47PTOXzwPBDsrFiq3VLbRjHSwf8rpqybQBH9MfzxGGxTaETQYOd6b4e4Ag6
52
+ y92abGna0bmIEb4+Tx9rQ10Uijh1POzvr/VTH4bbIPy9FbKrRsIQ24qDbNJRtOpE
53
+ RAOsIl+HOBTb252nx1kIRN5hqQx272AJCbCjKx8egcUQKffFVVCI0nye09v5CK+a
54
+ HiLJ8VOFx6w=
55
+ -----END CERTIFICATE-----
56
+ date: 2022-06-15 00:00:00.000000000 Z
12
57
  dependencies:
13
58
  - !ruby/object:Gem::Dependency
14
59
  name: console
@@ -173,14 +218,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
218
  requirements:
174
219
  - - ">="
175
220
  - !ruby/object:Gem::Version
176
- version: 3.1.0
221
+ version: 3.1.1
177
222
  required_rubygems_version: !ruby/object:Gem::Requirement
178
223
  requirements:
179
224
  - - ">="
180
225
  - !ruby/object:Gem::Version
181
226
  version: '0'
182
227
  requirements: []
183
- rubygems_version: 3.3.3
228
+ rubygems_version: 3.3.7
184
229
  signing_key:
185
230
  specification_version: 4
186
231
  summary: A concurrency framework for Ruby.
metadata.gz.sig ADDED
Binary file