Skip to content

Commit bdce203

Browse files
committed
Bump minor version.
1 parent 8686b5c commit bdce203

4 files changed

Lines changed: 48 additions & 4 deletions

File tree

context/getting-started.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ The installed handlers are snapshotted when they are installed. Later changes to
139139

140140
### Choosing a Signal Backend
141141

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.
143143

144144
```ruby
145145
require "async/signals"
@@ -150,13 +150,53 @@ handlers.trap(:TERM) do
150150
end
151151

152152
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.
154154
sleep
155155
end
156156
```
157157

158158
Use {ruby Async::Signals::Ignore} directly when a component is controlled by its parent and should not subscribe to process-wide signals.
159159

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+
160200
## Forking
161201

162202
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.

lib/async/signals/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
module Async
88
# @namespace
99
module Signals
10-
VERSION = "0.4.0"
10+
VERSION = "0.5.0"
1111
end
1212
end

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Please see the [project documentation](https://socketry.github.io/async-signals/
2424

2525
Please see the [project releases](https://socketry.github.io/async-signals/releases/index) for all releases.
2626

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+
2731
### v0.4.0
2832

2933
- Use `Fiber::Scheduler#fiber_interrupt` from `Context#raise` when available, falling back to `Thread#raise`.

releases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Releases
22

3-
## Unreleased
3+
## v0.5.0
44

55
- Change `Async::Signals.default` to select process signal handling only on the main thread when no fiber scheduler is installed.
66

0 commit comments

Comments
 (0)