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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/signals/context.rb +60 -6
- data/lib/async/signals/controller.rb +1 -1
- data/lib/async/signals/version.rb +1 -1
- data/readme.md +4 -0
- data/releases.md +4 -0
- data.tar.gz.sig +2 -2
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a6895e75a37685b99999d04d6fa72f0bf38956f5d2022a953348b69461986ff
|
|
4
|
+
data.tar.gz: b0a98e3b79cb845a4e676b0e3b4f2df64d94fca1903734162fb83784d76c27a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@
|
|
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
|
|
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
|
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
|
-
|
|
2
|
-
|
|
1
|
+
G�:�jy����ݿe�ʃ.�A�.���h�\R�zP���ٙŴ�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
metadata.gz.sig
CHANGED
|
Binary file
|