A
Aldric Giacomoni
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:
dictated_exams = DictatedExam.all
enumerate = Thread.new do
dictated_exams.each do |exam|
Thread.current[:id] = exam.id
end
end
print = Thread.new do
sleep 1
puts enumerate[:id]
end
end
... And I'm pretty much stuck here. I -think- what I want to do is
create a thread which won't end until after the main one ends, and loop
forever ?
Or maybe I want to repeatedly create a new thread which will print the
:id, then exit, until the 'enumerate' thread is done ?
I realize that I could do this in one process, without threads, but I
want to update the output, say, every second, instead of with every
element.
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:
dictated_exams = DictatedExam.all
enumerate = Thread.new do
dictated_exams.each do |exam|
Thread.current[:id] = exam.id
end
end
print = Thread.new do
sleep 1
puts enumerate[:id]
end
end
... And I'm pretty much stuck here. I -think- what I want to do is
create a thread which won't end until after the main one ends, and loop
forever ?
Or maybe I want to repeatedly create a new thread which will print the
:id, then exit, until the 'enumerate' thread is done ?
I realize that I could do this in one process, without threads, but I
want to update the output, say, every second, instead of with every
element.