Created
July 11, 2011 00:52
-
-
Save floere/1075153 to your computer and use it in GitHub Desktop.
When trapping Signals in your lib, please think about doing it like so:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When trapping Signals in your lib, please think about doing it like so: | |
# | |
old_handler = Signal.trap('SIGNALNAME') {} | |
Signal.trap('SIGNALNAME') do | |
# Whatever you'd like to do. | |
# Then: | |
old_handler.call | |
end |
True dat. The point is that Signal#trap doesn't yield, it just sets a handler and returns the old one immediately, so the assignment to old_handler happens straight away, before anything else can (except perhaps in another thread). The handler can only ever get called after the assignment.
Absolutely.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cjheath Actually, the moment it is called is not that important. It's firstly about local variable declaration and bindings, only secondly about the moment of the call.