Skip to content

Instantly share code, notes, and snippets.

@marcinbunsch
Created March 14, 2012 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcinbunsch/2038115 to your computer and use it in GitHub Desktop.
Save marcinbunsch/2038115 to your computer and use it in GitHub Desktop.
Gracefult quit
require "singleton"
class GracefulQuit
include Singleton
attr_accessor :breaker
def initialize
self.breaker = false
end
def self.enable
trap('INT') {
# force-quit on double ctrl-c
if self.instance.breaker
puts "Exiting"
exit
end
yield if block_given?
self.instance.breaker = true
}
end
def self.check(message = "Quitting")
if self.instance.breaker
yield if block_given?
puts message
exit
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment