Created
May 28, 2009 20:14
-
-
Save stereosupersonic/119540 to your computer and use it in GitHub Desktop.
timeout guard
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
def self.timeout_guard(sec) | |
main = Thread.current | |
timer = Thread.new { sleep sec; main.raise "Timeout after #{sec} seconds" } | |
begin | |
yield | |
ensure | |
timer.kill | |
end | |
end | |
# use timeout_guard(10) {do_somthing } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment