Created
January 6, 2010 23:28
-
-
Save kmdsbng/270805 to your computer and use it in GitHub Desktop.
This file contains 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
module DoubleCtrlCTrapper | |
TOLERANCE = 3 | |
def self.tolerance?(sec) | |
sec < TOLERANCE | |
end | |
def self.freq?(current) | |
b = @last_trapped && tolerance?(current - @last_trapped) | |
@last_trapped = current | |
b | |
end | |
def self.included(mod) | |
trap(:INT) { | |
exit if freq?(Time.now) | |
STDERR.puts 'To exit, press Ctrl-C twice' | |
} | |
end | |
end | |
if $0 == __FILE__ | |
include DoubleCtrlCTrapper | |
while(true) | |
sleep(1) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment