-
-
Save iwan/d417767e850f5ef61dec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'net/http' | |
def download_net_http(uris, thread_count) | |
queue = Queue.new | |
uris.map { |uri| queue << uri } | |
threads = thread_count.times.map do | |
Thread.new do | |
while !queue.empty? && uri = queue.pop | |
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme=='https') do |http| | |
request = Net::HTTP::Get.new(uri) | |
response = http.request request | |
write_file filename, response.body | |
end | |
end | |
end | |
end | |
threads.each(&:join) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment