async-signals 0.3.0 → 0.4.0

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: 892b6d001f6a23c4190ecb71cd652d63aea1a7331932a68f3b0f057f8cdf762e
4
- data.tar.gz: fd8a403c5abfe0a943ce0ec4c684ea5b6ba390f6c76006ed6772d0e12532d903
3
+ metadata.gz: 0a6895e75a37685b99999d04d6fa72f0bf38956f5d2022a953348b69461986ff
4
+ data.tar.gz: b0a98e3b79cb845a4e676b0e3b4f2df64d94fca1903734162fb83784d76c27a0
5
5
  SHA512:
6
- metadata.gz: cc9458635104d6f45cdcde03512d1e5e3dcaf09f21fa345bad891f678e2a5f6d80177c5dd7f84bc11e0a2d2b4b0c4582bba5cea9871bae6aafefaf320b05b124
7
- data.tar.gz: f885189f0ae71ef8c529bf17ae23c9ad080c22641716fd30e4c54c11bc0659786c030536b6448472ac9fb66667ed0736e180e0e746bfe3972cd9ad26589a8022
6
+ metadata.gz: 4dfb3560ef7de426d9166ac8b7ada5b0b38013126a871c7890c53ccb6c6c2061eb872ab7d829d8cfaeb84ba1c0ee337fb3cdf773ee82759ebdcb1771785ff83b
7
+ data.tar.gz: 33508c77b77fadac45d0d58413d7c84fc787ca1cbc89be6cd505ca100677926075d5e800132123b1127f80badf5236452b1337b250bdd4d1a31a9147ec55165c
checksums.yaml.gz.sig CHANGED
Binary file
@@ -7,19 +7,73 @@ module Async
7
7
  module Signals
8
8
  # Represents the execution context that installed a signal handler set.
9
9
  class Context
10
+ # Capture the current execution context.
11
+ # @returns [Context] The current execution context.
12
+ def self.current
13
+ thread = ::Thread.current
14
+ fiber = ::Fiber.current
15
+ scheduler = nil
16
+
17
+ if ::Fiber.respond_to?(:current_scheduler)
18
+ if current_scheduler = ::Fiber.current_scheduler
19
+ if current_scheduler.respond_to?(:fiber_interrupt)
20
+ scheduler = current_scheduler
21
+ end
22
+ end
23
+ end
24
+
25
+ self.new(thread, fiber, scheduler)
26
+ end
27
+
10
28
  # Initialize the context.
11
- def initialize
12
- # Capture both primitives so the public interface can evolve without
13
- # changing the handler arguments.
14
- @thread = ::Thread.current
15
- @fiber = ::Fiber.current
29
+ # @parameter thread [Thread] The thread that installed the handler set.
30
+ # @parameter fiber [Fiber] The fiber that installed the handler set.
31
+ # @parameter scheduler [Object | Nil] The scheduler that can interrupt the fiber.
32
+ def initialize(thread, fiber, scheduler = nil)
33
+ @thread = thread
34
+ @fiber = fiber
35
+ @scheduler = scheduler
16
36
  end
17
37
 
18
- # Raise an exception in the thread that installed the handler set.
38
+ # Raise an exception in the execution context that installed the handler set.
19
39
  # @parameter arguments [Array] The arguments to pass to {Thread#raise}.
20
40
  def raise(*arguments)
41
+ if @scheduler
42
+ return @scheduler.fiber_interrupt(@fiber, exception_for(arguments))
43
+ end
44
+
21
45
  @thread.raise(*arguments)
22
46
  end
47
+
48
+ private def exception_for(arguments)
49
+ case arguments.size
50
+ when 0
51
+ ::RuntimeError.exception
52
+ when 1
53
+ argument = arguments.first
54
+
55
+ case argument
56
+ when ::String
57
+ ::RuntimeError.exception(argument)
58
+ else
59
+ begin
60
+ exception = argument.exception
61
+ rescue NoMethodError
62
+ ::Kernel.raise ::TypeError, "exception class/object expected"
63
+ end
64
+
65
+ unless exception.is_a?(::Exception)
66
+ ::Kernel.raise ::TypeError, "exception object expected"
67
+ end
68
+
69
+ exception
70
+ end
71
+ else
72
+ exception = arguments.first.exception(arguments[1])
73
+ exception.set_backtrace(arguments[2]) if arguments[2]
74
+ exception
75
+ end
76
+ end
23
77
  end
24
78
  end
25
79
  end
@@ -91,7 +91,7 @@ module Async
91
91
  def initialize(controller, handlers)
92
92
  @controller = controller
93
93
  @handlers = handlers
94
- @context = Context.new
94
+ @context = Context.current
95
95
  end
96
96
 
97
97
  # @attribute [Context] The context that installed this registration.
@@ -7,6 +7,6 @@
7
7
  module Async
8
8
  # @namespace
9
9
  module Signals
10
- VERSION = "0.3.0"
10
+ VERSION = "0.4.0"
11
11
  end
12
12
  end
data/readme.md CHANGED
@@ -24,6 +24,10 @@ Please see the [project documentation](https://socketry.github.io/async-signals/
24
24
 
25
25
  Please see the [project releases](https://socketry.github.io/async-signals/releases/index) for all releases.
26
26
 
27
+ ### v0.4.0
28
+
29
+ - Use `Fiber::Scheduler#fiber_interrupt` from `Context#raise` when available, falling back to `Thread#raise`.
30
+
27
31
  ### v0.3.0
28
32
 
29
33
  - Pass the installing context as the second signal handler argument and allow handler exceptions to propagate.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.4.0
4
+
5
+ - Use `Fiber::Scheduler#fiber_interrupt` from `Context#raise` when available, falling back to `Thread#raise`.
6
+
3
7
  ## v0.3.0
4
8
 
5
9
  - Pass the installing context as the second signal handler argument and allow handler exceptions to propagate.
data.tar.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- ,�7Hk22"9������;-U�`XD*ց;7�O�ї_��C孛���1��<E���v�4����C$�b"i����c�ÇyP�@������<���K�Q?\8����O��U:��)|S�;�(A� �
2
- �nn������J�f�޼Ԁ�~!��X�ٜP�(��8b�D�$��B�vwz��fs�-G/E�K*~�X��&_���
1
+ G�:�jy����ݿe�ʃ.�A�.���h�\RzP���ٙŴ�K��lf��P�����GЍ����t���6�Or�c��N��ftm ���ގ:]b'��ҁsw���f*�6˲=��B̾�҅�t^퀈*�T4�%j�5���x�5�\,�F(&��N��U�"�����i>�bA_CkἯ
2
+ �~x.1�ѕ�P
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-signals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file