Hi,

I ran the script(script a) in irb mode and I find it never jumps to next 
element without input from outside/console, which is not what I want. 
Here is my requirement for the timeout: 1) iterate an array 2)when 
jumping from one element to the next wait for 5 seconds for the input. 
If no input after 5 seconds then jump to the next element. If there is 
an input then process the input. After that also jump to the next 
element.

Also I ran two very short scripts (script b and script c) after reading 
doc for Timeout. I find that one works and other doesn't work: without 
input from the console the timeout does not work.

Any idea?

Thanks,

Li




####script a: without input the array never move forward ####

C:\Users\Alex>irb
irb(main):001:0> require 'timeout'
=> false
irb(main):002:0> a=(1..10).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
irb(main):003:0>
irb(main):004:0* STDOUT.sync=true
=> true
irb(main):005:0>
irb(main):006:0* a.each do |e|
irb(main):007:1*   print "> "
irb(main):008:1>
irb(main):009:1*   begin
irb(main):010:2*     Timeout.timeout(5) do
irb(main):011:3*       x=gets
irb(main):012:3>       puts "you entered: #{x}"
irb(main):013:3>     end
irb(main):014:2>   rescue Timeout::Error
irb(main):015:2>   end
irb(main):016:1>
irb(main):017:1*   puts e
irb(main):018:1> end
>


###script b doesn't work#####

C:\Users\Alex>irb
irb(main):001:0> require 'timeout'
=> false
irb(main):002:0> Timeout.timeout(10){gets}



###script c works by raising an error###

C:\Users\Alex>irb
irb(main):001:0> require 'timeout'
=> false
irb(main):002:0>
irb(main):003:0* Timeout.timeout(10){sleep}
c:/ruby/lib/ruby/1.8/timeout.rb:54:in `irb_binding': execution expired 
(Timeout::Error)
        from c:/ruby/lib/ruby/1.8/timeout.rb:56:in `timeout'
        from (irb):3:in `irb_binding'
        from c:/ruby/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'
        from c:/ruby/lib/ruby/1.8/irb/workspace.rb:52



-- 
Posted via http://www.ruby-forum.com/.