From: Mike Houghton Date: 2006-11-17T03:34:09+09:00 Subject: Re: Threading Question -- sorry Sylvain Joyeux wrote: > [previous code snipped] >> timer = Timer.new( 1,5){puts "x"} >> timer.start > <= the application finishes here > > You have to call #join on your thread or the application finishes and > the > thread is killed > > Sylvain Yes! Thanks, the light just went on... class Timer def initialize( period, count, &action ) @period = period @count = count @action = action end #initialize def start @thr = Thread.new do @count.times do @action.call sleep(@period) end #do end #do end #start def join @thr.join end end #class Timer timer = Timer.new( 1,5){puts "x"} timer.start timer.join Ideally what I'd now like to do is make the Timer class such that I don't need to have a public join method and the @thr.join is, somehow, called intrinsically. -- Posted via http://www.ruby-forum.com/.