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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a6895e75a37685b99999d04d6fa72f0bf38956f5d2022a953348b69461986ff
4
- data.tar.gz: b0a98e3b79cb845a4e676b0e3b4f2df64d94fca1903734162fb83784d76c27a0
3
+ metadata.gz: 969ede7a2ae47c0fe9599becb2508e5c967fae6f9794724441b0c26bb206d94c
4
+ data.tar.gz: 7498cf8e1e038d238655cfb86d942990d41fa1bd8defde3e31d746c05b7229b1
5
5
  SHA512:
6
- metadata.gz: 4dfb3560ef7de426d9166ac8b7ada5b0b38013126a871c7890c53ccb6c6c2061eb872ab7d829d8cfaeb84ba1c0ee337fb3cdf773ee82759ebdcb1771785ff83b
7
- data.tar.gz: 33508c77b77fadac45d0d58413d7c84fc787ca1cbc89be6cd505ca100677926075d5e800132123b1127f80badf5236452b1337b250bdd4d1a31a9147ec55165c
6
+ metadata.gz: 5fa34ee6b5d702e0da640a56654f57c1dee5e3d6190ed37d9d78d5d3ea249d7acba78c5d7ad3c01c7e08cd882ab49b08e4dcbba0bf5e9914218c6fd954df6574
7
+ data.tar.gz: 9861c7a96dbbd194ccf2243599e77e66bf50b949ce593d0f4b369da238d7e0b6b69aaebbabd25979b2e8187af2a66e692312618f86635ae747d588767bcc8f6e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -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 while running on the main thread. It returns {ruby Async::Signals} on the main thread and {ruby Async::Signals::Ignore} on other threads.
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 on the main thread.
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 while running on the main thread. It returns {ruby Async::Signals} on the main thread and {ruby Async::Signals::Ignore} on other threads.
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 on the main thread.
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.
@@ -7,6 +7,6 @@
7
7
  module Async
8
8
  # @namespace
9
9
  module Signals
10
- VERSION = "0.4.0"
10
+ VERSION = "0.5.0"
11
11
  end
12
12
  end
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 thread.
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
- self
28
- else
29
- Ignore
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
@@ -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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file