Skip to content

Instantly share code, notes, and snippets.

@lostseaway
Created April 6, 2014 03:38
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 lostseaway/10001198 to your computer and use it in GitHub Desktop.
Save lostseaway/10001198 to your computer and use it in GitHub Desktop.
# def repeat_every(interval)
# Thread.new do
# loop do
# start_time = Time.now
# yield
# elapsed = Time.now - start_time
# sleep([interval - elapsed, 0].max)
# end
# end
# end
# start_time = Time.now.to_i
# hr = 0;
# min = 0;
# sec = 0;
# thread = repeat_every(1) do
# # system ("clear")
# now = Time.now.to_i - start_time
# sec = now%60
# if now > 60
# min = now/60
# end
# if now > 3600
# hr = now/3600
# end
# puts hr.to_s + ":" + min.to_s + ":" + sec.to_s
# end
# th = repeat_every(1)do
# puts "in"
# com = gets
# puts com+"asdfasdfasf"
# if com=="s"
# thread.end
# puts "TIME STOP!"
# puts hr.to_s + ":" + min.to_s + ":" + sec.to_s
# end
# end
# puts "Doing other stuff..."
# th.join
# thread.join
user_input = Thread.new do
print "Enter something: "
Thread.current[:value] = gets.chomp
end
timer = Thread.new { sleep 3; user_input.kill; puts }
user_input.join
if user_input[:value]
puts "User entered #{user_input[:value]}"
else
puts "Timer expired"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment