From: "Iñaki Baz Castillo" Date: 2008-10-06T04:20:40+09:00 Subject: Re: timeout question 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 ------------- -- Iñaki Baz Castillo