async-signals 0.4.0 → 0.5.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/context/getting-started.md +42 -2
- data/guides/getting-started/readme.md +42 -2
- data/lib/async/signals/version.rb +1 -1
- data/lib/async/signals.rb +7 -4
- data/readme.md +4 -0
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- 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: 969ede7a2ae47c0fe9599becb2508e5c967fae6f9794724441b0c26bb206d94c
|
|
4
|
+
data.tar.gz: 7498cf8e1e038d238655cfb86d942990d41fa1bd8defde3e31d746c05b7229b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5fa34ee6b5d702e0da640a56654f57c1dee5e3d6190ed37d9d78d5d3ea249d7acba78c5d7ad3c01c7e08cd882ab49b08e4dcbba0bf5e9914218c6fd954df6574
|
|
7
|
+
data.tar.gz: 9861c7a96dbbd194ccf2243599e77e66bf50b949ce593d0f4b369da238d7e0b6b69aaebbabd25979b2e8187af2a66e692312618f86635ae747d588767bcc8f6e
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/context/getting-started.md
CHANGED
|
@@ -139,7 +139,7 @@ The installed handlers are snapshotted when they are installed. Later changes to
|
|
|
139
139
|
|
|
140
140
|
### Choosing a Signal Backend
|
|
141
141
|
|
|
142
|
-
Use {ruby Async::Signals.default} when a component should install process signal handlers only
|
|
142
|
+
Use {ruby Async::Signals.default} when a component should install process signal handlers only when it appears to own the process signal boundary. It returns {ruby Async::Signals} on the main thread when no fiber scheduler is installed, and {ruby Async::Signals::Ignore} otherwise.
|
|
143
143
|
|
|
144
144
|
```ruby
|
|
145
145
|
require "async/signals"
|
|
@@ -150,13 +150,53 @@ handlers.trap(:TERM) do
|
|
|
150
150
|
end
|
|
151
151
|
|
|
152
152
|
Async::Signals.default.install(handlers) do
|
|
153
|
-
# Process signal handlers are active only
|
|
153
|
+
# Process signal handlers are active only when using the default signal backend.
|
|
154
154
|
sleep
|
|
155
155
|
end
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
Use {ruby Async::Signals::Ignore} directly when a component is controlled by its parent and should not subscribe to process-wide signals.
|
|
159
159
|
|
|
160
|
+
### Using Signals with Async
|
|
161
|
+
|
|
162
|
+
When a component runs inside an existing Async event loop, it should not implicitly take ownership of process-wide signals. In that case, {ruby Async::Signals.default} returns {ruby Async::Signals::Ignore}, so installing handlers through the default backend becomes a no-op.
|
|
163
|
+
|
|
164
|
+
```ruby
|
|
165
|
+
require "async"
|
|
166
|
+
require "async/signals"
|
|
167
|
+
|
|
168
|
+
handlers = Async::Signals::Handlers.new
|
|
169
|
+
handlers.trap(:TERM) do
|
|
170
|
+
puts "Stopping..."
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
Async do
|
|
174
|
+
Async::Signals.default.install(handlers) do
|
|
175
|
+
# No process signal traps are installed here.
|
|
176
|
+
sleep
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
If a component running inside an Async event loop is intended to own process signal handling, pass {ruby Async::Signals} explicitly instead of using the default backend.
|
|
182
|
+
|
|
183
|
+
```ruby
|
|
184
|
+
require "async"
|
|
185
|
+
require "async/signals"
|
|
186
|
+
|
|
187
|
+
handlers = Async::Signals::Handlers.new
|
|
188
|
+
handlers.trap(:TERM) do |signal, context|
|
|
189
|
+
context.raise(Interrupt)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
Async do
|
|
193
|
+
Async::Signals.install(handlers) do
|
|
194
|
+
# Process signal traps are explicitly installed here.
|
|
195
|
+
sleep
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
```
|
|
199
|
+
|
|
160
200
|
## Forking
|
|
161
201
|
|
|
162
202
|
Signal traps are inherited across `fork`. On Ruby implementations that support `Process._fork`, `async-signals` automatically resets inherited signal state in the forked child so the child does not keep handler registrations from the parent process.
|
|
@@ -139,7 +139,7 @@ The installed handlers are snapshotted when they are installed. Later changes to
|
|
|
139
139
|
|
|
140
140
|
### Choosing a Signal Backend
|
|
141
141
|
|
|
142
|
-
Use {ruby Async::Signals.default} when a component should install process signal handlers only
|
|
142
|
+
Use {ruby Async::Signals.default} when a component should install process signal handlers only when it appears to own the process signal boundary. It returns {ruby Async::Signals} on the main thread when no fiber scheduler is installed, and {ruby Async::Signals::Ignore} otherwise.
|
|
143
143
|
|
|
144
144
|
```ruby
|
|
145
145
|
require "async/signals"
|
|
@@ -150,13 +150,53 @@ handlers.trap(:TERM) do
|
|
|
150
150
|
end
|
|
151
151
|
|
|
152
152
|
Async::Signals.default.install(handlers) do
|
|
153
|
-
# Process signal handlers are active only
|
|
153
|
+
# Process signal handlers are active only when using the default signal backend.
|
|
154
154
|
sleep
|
|
155
155
|
end
|
|
156
156
|
```
|
|
157
157
|
|
|
158
158
|
Use {ruby Async::Signals::Ignore} directly when a component is controlled by its parent and should not subscribe to process-wide signals.
|
|
159
159
|
|
|
160
|
+
### Using Signals with Async
|
|
161
|
+
|
|
162
|
+
When a component runs inside an existing Async event loop, it should not implicitly take ownership of process-wide signals. In that case, {ruby Async::Signals.default} returns {ruby Async::Signals::Ignore}, so installing handlers through the default backend becomes a no-op.
|
|
163
|
+
|
|
164
|
+
```ruby
|
|
165
|
+
require "async"
|
|
166
|
+
require "async/signals"
|
|
167
|
+
|
|
168
|
+
handlers = Async::Signals::Handlers.new
|
|
169
|
+
handlers.trap(:TERM) do
|
|
170
|
+
puts "Stopping..."
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
Async do
|
|
174
|
+
Async::Signals.default.install(handlers) do
|
|
175
|
+
# No process signal traps are installed here.
|
|
176
|
+
sleep
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
If a component running inside an Async event loop is intended to own process signal handling, pass {ruby Async::Signals} explicitly instead of using the default backend.
|
|
182
|
+
|
|
183
|
+
```ruby
|
|
184
|
+
require "async"
|
|
185
|
+
require "async/signals"
|
|
186
|
+
|
|
187
|
+
handlers = Async::Signals::Handlers.new
|
|
188
|
+
handlers.trap(:TERM) do |signal, context|
|
|
189
|
+
context.raise(Interrupt)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
Async do
|
|
193
|
+
Async::Signals.install(handlers) do
|
|
194
|
+
# Process signal traps are explicitly installed here.
|
|
195
|
+
sleep
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
```
|
|
199
|
+
|
|
160
200
|
## Forking
|
|
161
201
|
|
|
162
202
|
Signal traps are inherited across `fork`. On Ruby implementations that support `Process._fork`, `async-signals` automatically resets inherited signal state in the forked child so the child does not keep handler registrations from the parent process.
|
data/lib/async/signals.rb
CHANGED
|
@@ -20,14 +20,17 @@ module Async
|
|
|
20
20
|
CONTROLLER
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
# The default signal backend for the current
|
|
23
|
+
# The default signal backend for the current context.
|
|
24
24
|
# @returns [Async::Signals | Async::Signals::Ignore] The default signal backend.
|
|
25
25
|
def self.default
|
|
26
26
|
if ::Thread.current == ::Thread.main
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
# TruffleRuby does not currently expose `Fiber.scheduler`:
|
|
28
|
+
unless ::Fiber.respond_to?(:scheduler) && ::Fiber.scheduler
|
|
29
|
+
return self
|
|
30
|
+
end
|
|
30
31
|
end
|
|
32
|
+
|
|
33
|
+
return Ignore
|
|
31
34
|
end
|
|
32
35
|
|
|
33
36
|
# Install signal handlers using the process-wide signal controller.
|
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.5.0
|
|
28
|
+
|
|
29
|
+
- Change `Async::Signals.default` to select process signal handling only on the main thread when no fiber scheduler is installed.
|
|
30
|
+
|
|
27
31
|
### v0.4.0
|
|
28
32
|
|
|
29
33
|
- Use `Fiber::Scheduler#fiber_interrupt` from `Context#raise` when available, falling back to `Thread#raise`.
|
data/releases.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Releases
|
|
2
2
|
|
|
3
|
+
## v0.5.0
|
|
4
|
+
|
|
5
|
+
- Change `Async::Signals.default` to select process signal handling only on the main thread when no fiber scheduler is installed.
|
|
6
|
+
|
|
3
7
|
## v0.4.0
|
|
4
8
|
|
|
5
9
|
- Use `Fiber::Scheduler#fiber_interrupt` from `Context#raise` when available, falling back to `Thread#raise`.
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
|
Binary file
|