From: Li Chen Date: 2008-10-06T09:21:58+09:00 Subject: Re: timeout question I単aki Baz Castillo wrote: > El Domingo, 5 de Octubre de 2008, Li Chen escribi坦: >> Hi all, >> >> I iterate an array. During jumping from one element to the next one I >> need to get user input from the console. 1) If not input after 5 seconds >> I have to jump to the next element. 2)If there is an input within 5 >> seconds I go for processing the input and then jump to the next >> element. >> >> I don't know how to implement the code for question 1. I wonder if >> anyone there has a good idea. > > This works for me: > > ------------- > ARRAY = %w{A B C D E} > > ARRAY.each do |letter| > > @t_input = Thread.new do > input = gets > puts "#{letter} - String entered by user: #{input}" > end > > @t_timer= Thread.new do > sleep 3 > puts "Timeout, going to next element..." > @t_input.terminate > end > > @t_input.join > @t_timer.terminate > > end It doesn't work for me. The timeout hangs out for ever if no input is available. Li -- Posted via http://www.ruby-forum.com/.