Panagiotis Atmatzidis
2016-03-29 11:15:38 UTC
Hello,
I have a ruby script which uses a thread pool to fetch JSON objects via http. Now, Iâm using a static number of pages (see pseudo-code below) but I need to introduce a condition and stop the process when that condition is met (e.g. request returns a 404).
The structure now looks like this:
1.upto(100) do |n|
threads << Thread.new { ... }
end
threads.join()
What I donât understand is how to apply a sort of break when a condition is met. Iâm thinking something along the lines:
x = true
while x
threads << Thread.new {
âŠ
break unless x
}
end
threads.join()
Will the above approach work? Is there a better one? How do people deal in these situations with threads?
thanks!
Panagiotis (atmosx) Atmatzidis
email: ***@convalesco.org
URL: http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5
"Everyone thinks of changing the world, but no one thinks of changing himself.â - Leo Tolstoy
I have a ruby script which uses a thread pool to fetch JSON objects via http. Now, Iâm using a static number of pages (see pseudo-code below) but I need to introduce a condition and stop the process when that condition is met (e.g. request returns a 404).
The structure now looks like this:
1.upto(100) do |n|
threads << Thread.new { ... }
end
threads.join()
What I donât understand is how to apply a sort of break when a condition is met. Iâm thinking something along the lines:
x = true
while x
threads << Thread.new {
âŠ
break unless x
}
end
threads.join()
Will the above approach work? Is there a better one? How do people deal in these situations with threads?
thanks!
Panagiotis (atmosx) Atmatzidis
email: ***@convalesco.org
URL: http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5
"Everyone thinks of changing the world, but no one thinks of changing himself.â - Leo Tolstoy