-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
When you trap a signal, you replace any previous definition with your own, overriding any default behavior.
This is an additional problem.
In Ruby-land Signal.trap returns the previous handler,
so you can safely chain them.
Crystal currently has no equivalent to this.
This is problematic when for example a shard needs
to add a signal-handler. As of today it has no way to
preserve (or even detect) an already attached handler.
I'd like to propose the following syntax to enable signal handler chaining:
Signal::INT.trap do
puts "Trap 1"
exit
end
Signal::INT.trap do |previous_handler|
puts "Trap 2"
previous_handler.call
end
Output on signal:
Trap 2
Trap 1
Originally posted by @m-o-e in #8687 (comment)
jwoertink, MistressRemilia, n-rodriguez and cyangle