Skip to content

Instantly share code, notes, and snippets.

@stereosupersonic
Created May 28, 2009 20:14
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 stereosupersonic/119540 to your computer and use it in GitHub Desktop.
Save stereosupersonic/119540 to your computer and use it in GitHub Desktop.
timeout guard
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