Aldric Giacomoni wrote:
> I want to do this in a Rake task, but the concept is Ruby. I would like
> to use one thread to do the work, and one thread to periodically tell me
> "We're working on element x now". I'm trying to work from this page:
> http://ruby-doc.org/docs/ProgrammingRuby/html/tut_threads.html
> Here is basically what I have:
> 
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?
-- 
Posted via http://www.ruby-forum.com/.