From: Brian Candler Date: 2009-12-16T07:16:45+09:00 Subject: Re: Using threads to show progress Aldric Giacomoni wrote: > I've successfully implemented it this way: > > desc "Go through dictated exams and show IDs" > task(:showSomeIDs => :environment) do > dictated_exams = DictatedExam.all > enumerate = Thread.new do > dictated_exams.each do |exam| > Thread.current[:id] = exam.id > end > end > print = Thread.new do > while true > sleep 0.01 > puts enumerate[:id] > end > end > enumerate.join > print.kill > end > > Is there a more elegant way to do it? while enumerate.alive? puts enumerate[:id] sleep 1 end Then you don't need a print thread at all (just do it from the 'main' thread) -- Posted via http://www.ruby-forum.com/.