Hi guys! Hope you`ll find some time to assist with any ideas
i have an array of links and a number of steps that needs to be done to
each of those links.
there are always the same amount of links in array..so basically i can
do everything manually
i was wondering how can i create the new thread for processing each of
those links , maybe there`s a way of doing something like this :
array.each do |link|
a = Thread.new {....}
a.join
end
···
--
Posted via http://www.ruby-forum.com/.
Vlad Smith wrote:
Hi guys! Hope you`ll find some time to assist with any ideas
i have an array of links and a number of steps that needs to be done to
each of those links.
there are always the same amount of links in array..so basically i can
do everything manually
i was wondering how can i create the new thread for processing each of
those links , maybe there`s a way of doing something like this :
array.each do |link|
a = Thread.new {....}
a.join
end
That almost works, except it will block on each thread before starting the next.
threads =
array.each do |link|
threads << Thread.new {....}
end
threads.each do |t|
t.join
end
-Justin
Your code won't run anything in parallel. Thread#join will wait until
the thread is finished.
Try mapping your array to a list of threads, then iterating over that
list calling join:
array.map { |link|
Thread.new(link) { |l| ... }
}.each { |thread| thread.join }
···
On Thu, Jul 02, 2009 at 05:44:00AM +0900, Vlad Smith wrote:
Hi guys! Hope you`ll find some time to assist with any ideas
i have an array of links and a number of steps that needs to be done to
each of those links.
there are always the same amount of links in array..so basically i can
do everything manually
i was wondering how can i create the new thread for processing each of
those links , maybe there`s a way of doing something like this :
array.each do |link|
a = Thread.new {....}
a.join
end
--
Aaron Patterson
http://tenderlovemaking.com/
thanks everybody, works works just great!
···
--
Posted via http://www.ruby-forum.com/.