Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created April 15, 2010 14:22
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 ngauthier/367139 to your computer and use it in GitHub Desktop.
Save ngauthier/367139 to your computer and use it in GitHub Desktop.
#!/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