Skip to content

Instantly share code, notes, and snippets.

@lstoll
Created November 6, 2012 02:26
Show Gist options
  • Save lstoll/4022172 to your computer and use it in GitHub Desktop.
Save lstoll/4022172 to your computer and use it in GitHub Desktop.
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