Created
November 6, 2012 02:26
-
-
Save lstoll/4022172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
to_parse = Queue.new | |
to_fetch = Queue.new | |
threads = [] | |
threads << Thread.new do | |
while true do | |
if queue.size > MAX_WE_WANT_QUEUED | |
sleep 5 | |
else | |
to_parse << get_the_file_to_parse | |
end | |
end | |
end | |
threads << Thread.new do | |
to_fetch << result_of_parsing(to_parse.deq) | |
end | |
threads.concat (1..20).map do |i| | |
Thread.new do | |
download_file(to_fetch.deq) | |
end | |
end | |
threads.each {|t| t.join } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment