Created
April 15, 2010 14:22
-
-
Save ngauthier/367139 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
#!/usr/bin/env ruby | |
def sleep_for_5 | |
puts 'gonna sleep for 5' | |
sleep(5) | |
puts 'yawn!' | |
end | |
def sleep_for_15 | |
puts 'gonna sleep for 15' | |
sleep(15) | |
puts 'yawn!' | |
end | |
t = Thread.new do | |
# toggle for one that succeeds: | |
# sleep_for_5 | |
# And one that fails: | |
sleep_for_15 | |
end | |
start = Time.now | |
loop do | |
if !t.status # if the thread is done | |
t.join | |
break | |
else | |
if Time.now - start > 10 | |
puts 'timeout!' | |
t.kill | |
t.join | |
break | |
end | |
end | |
sleep(0.25) | |
end | |
puts 'Done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment