async 2.13.0 → 2.14.1

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: fe1866e547e6705255fdce380d3e5532964d0b74c009579f481f3c3fb8086b6c
4
- data.tar.gz: 5d3ac4bbbb8579cbcc85944c447dcea2e6b4b2408af9ad3829eace9934067199
3
+ metadata.gz: ffbf235f3425b766c8eedfcdb2b03f86569e43ab1cdda3bd44f74c1b25f516b7
4
+ data.tar.gz: 1d71883b2151b5eb0f23daf27221ac091d352809a0ef1f687f282696cd22ae79
5
5
  SHA512:
6
- metadata.gz: e208dc1b43979431fe3bf36acdcbebb97306bf32ec8471ea9081763d737865e47486dc798d5704ed829b27b16385f48425c4af687eda169f94e36f1c32c8ec86
7
- data.tar.gz: d961dafc64289d00b1e99b3245577d5e549365d415e6628cba39af4a5b0d58fc15da468d880fa1796c97351ff83ba2814d073ebbab18aaeaef6a3eb50be26efb
6
+ metadata.gz: a00499f9ea43ffee3e6a5cf65dee14f67c5dcd167cb68e1b5da7c11bcef51c06da9c8c2d7a0606f72e5802520f7b9837f128d8425ade3de75111ca16a4cc9c10
7
+ data.tar.gz: f65b60522c85e07a17fdc345944c06e7447095682afea0bd2b7dcbf462deeeb7dcb6053e82eefc96cc259b10d6b0849803b8f22356feb10a21666a5ab134f6d6
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/async/task.rb CHANGED
@@ -13,6 +13,8 @@ require 'console/event/failure'
13
13
  require_relative 'node'
14
14
  require_relative 'condition'
15
15
 
16
+ Fiber.attr_accessor :async_task
17
+
16
18
  module Async
17
19
  # Raised when a task is explicitly stopped.
18
20
  class Stop < Exception
@@ -186,6 +188,15 @@ module Async
186
188
 
187
189
  schedule do
188
190
  @block.call(self, *arguments)
191
+ rescue => error
192
+ # I'm not completely happy with this overhead, but the alternative is to not log anything which makes debugging extremely difficult. Maybe we can introduce a debug wrapper which adds extra logging.
193
+ if @finished.nil?
194
+ Console::Event::Failure.for(error).emit("Task may have ended with unhandled exception.", severity: :warn)
195
+ # else
196
+ # Console::Event::Failure.for(error).emit(self, severity: :debug)
197
+ end
198
+
199
+ raise
189
200
  end
190
201
  else
191
202
  raise RuntimeError, "Task already running!"
@@ -316,13 +327,13 @@ module Async
316
327
  # @returns [Task]
317
328
  # @raises[RuntimeError] If task was not {set!} for the current fiber.
318
329
  def self.current
319
- Thread.current[:async_task] or raise RuntimeError, "No async task available!"
330
+ Fiber.current.async_task or raise RuntimeError, "No async task available!"
320
331
  end
321
332
 
322
333
  # Check if there is a task defined for the current fiber.
323
334
  # @returns [Interface(:async) | Nil]
324
335
  def self.current?
325
- Thread.current[:async_task]
336
+ Fiber.current.async_task
326
337
  end
327
338
 
328
339
  # @returns [Boolean] Whether this task is the currently executing task.
@@ -354,21 +365,10 @@ module Async
354
365
  @status = :completed
355
366
  end
356
367
 
357
- # 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.
358
- def failed!(exception = false, propagate = true)
368
+ # State transition into the failed state.
369
+ def failed!(exception = false)
359
370
  @result = exception
360
371
  @status = :failed
361
-
362
- if exception
363
- if propagate
364
- raise exception
365
- elsif @finished.nil?
366
- # If no one has called wait, we log this as a warning:
367
- Console::Event::Failure.for(exception).emit(self, "Task may have ended with unhandled exception.", severity: :warn)
368
- else
369
- Console::Event::Failure.for(exception).emit(self, severity: :debug)
370
- end
371
- end
372
372
  end
373
373
 
374
374
  def stopped!
@@ -399,30 +399,26 @@ module Async
399
399
 
400
400
  def schedule(&block)
401
401
  @fiber = Fiber.new(annotation: self.annotation) do
402
- set!
403
-
404
402
  begin
405
403
  completed!(yield)
406
- # Console.debug(self) {"Task was completed with #{@children.size} children!"}
407
404
  rescue Stop
408
405
  stopped!
409
406
  rescue StandardError => error
410
- failed!(error, false)
407
+ failed!(error)
411
408
  rescue Exception => exception
412
- failed!(exception, true)
409
+ failed!(exception)
410
+
411
+ # This is a critical failure, we should stop the reactor:
412
+ raise
413
413
  ensure
414
414
  # Console.info(self) {"Task ensure $! = #{$!} with #{@children&.size.inspect} children!"}
415
415
  finish!
416
416
  end
417
417
  end
418
418
 
419
+ @fiber.async_task = self
420
+
419
421
  self.root.resume(@fiber)
420
422
  end
421
-
422
- # Set the current fiber's `:async_task` to this task.
423
- def set!
424
- # This is actually fiber-local:
425
- Thread.current[:async_task] = self
426
- end
427
423
  end
428
424
  end
data/lib/async/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2024, by Samuel Williams.
5
5
 
6
6
  module Async
7
- VERSION = "2.13.0"
7
+ VERSION = "2.14.1"
8
8
  end
data/readme.md CHANGED
@@ -19,20 +19,17 @@ Async is a composable asynchronous I/O framework for Ruby based on [io-event](ht
19
19
 
20
20
  Please see the [project documentation](https://socketry.github.io/async/) for more details.
21
21
 
22
- - [Getting Started](https://socketry.github.io/async/guides/getting-started/index) - This guide shows how to add
23
- async to your project and run code asynchronously.
22
+ - [Getting Started](https://socketry.github.io/async/guides/getting-started/index) - This guide shows how to add async to your project and run code asynchronously.
24
23
 
25
- - [Asynchronous Tasks](https://socketry.github.io/async/guides/asynchronous-tasks/index) - This guide explains how
26
- asynchronous tasks work and how to use them.
24
+ - [Asynchronous Tasks](https://socketry.github.io/async/guides/asynchronous-tasks/index) - This guide explains how asynchronous tasks work and how to use them.
27
25
 
28
- - [Event Loop](https://socketry.github.io/async/guides/event-loop/index) - This guide gives an overview of how the
29
- event loop is implemented.
26
+ - [Event Loop](https://socketry.github.io/async/guides/event-loop/index) - This guide gives an overview of how the event loop is implemented.
30
27
 
31
- - [Compatibility](https://socketry.github.io/async/guides/compatibility/index) - This guide gives an overview of the
32
- compatibility of Async with Ruby and other frameworks.
28
+ - [Compatibility](https://socketry.github.io/async/guides/compatibility/index) - This guide gives an overview of the compatibility of Async with Ruby and other frameworks.
33
29
 
34
- - [Best Practices](https://socketry.github.io/async/guides/best-practices/index) - This guide gives an overview of
35
- best practices for using Async.
30
+ - [Best Practices](https://socketry.github.io/async/guides/best-practices/index) - This guide gives an overview of best practices for using Async.
31
+
32
+ - [Debugging](https://socketry.github.io/async/guides/debugging/index) - This guide explains how to debug issues with programs that use Async.
36
33
 
37
34
  ## Contributing
38
35
 
data.tar.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- `yROr��ٵOaOf`�~����l���_Y�~�A)�.v���2o'oiVQ���~�Mu ��K���~�{Vut�˼�͛�6*�!����?23 .��
2
- � uk����Y@u$E��GB��2��M�!E&ٳ���n7�ʀv��P�@5��pw�3���8��m{h���jW���LkJ���� 5}n_ �j �����(��ALq�⥉��E1�4�k?��2>�U���M�[ �E����Mj��8� �)�^? ]�����{|9��S�A�=�\��
3
- ���`�G���VhL�&�_����_�gǁ6��[�E:���nk�p����-Y��� xD��gG�f�&�)��!�[5N1��Ο��Cc�l�ӕ
1
+ (��6�d��Gl!剟��ץ�4��5��wsIb��<^&5��5��@g�{\�rR_���O���o�e ĉ�F�s�RL6A*��LΆ��Ԏz5v-N�ZF�_\k�<H"`�D�*�[�P���sE`x�X��4�`v->�f`�ge�~?\�m�`�QB�&��y��uk ]^�=tB}=�ԯ�\����ib�;�.2>����TY������&=����o��8�㱑�x�:����s��c�/^k��˷c?L qQ�ߤ�+�b���9LEp�CWx_���?z����hK�Y��I@;5�D�7t�lE��x�S�����!~ ᤪϪԆ��K�`-�f`��
2
+ �6�&s�9s�m�SK�;U�o8��@
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.13.0
4
+ version: 2.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -62,7 +62,7 @@ cert_chain:
62
62
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
63
63
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
64
64
  -----END CERTIFICATE-----
65
- date: 2024-07-12 00:00:00.000000000 Z
65
+ date: 2024-07-15 00:00:00.000000000 Z
66
66
  dependencies:
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: console
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  requirements: []
175
- rubygems_version: 3.5.9
175
+ rubygems_version: 3.5.11
176
176
  signing_key:
177
177
  specification_version: 4
178
178
  summary: A concurrency framework for Ruby.
metadata.gz.sig CHANGED
Binary file