Created
October 12, 2018 18:53
-
-
Save kopylovvlad/0b400e74853defbebe0c1a6ef7b25969 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
require 'open-uri' | |
urls = [ | |
'https://www.google.com/', | |
'https://www.youtube.com/', | |
'http://www.rubyflow.com', | |
'https://rubyonrails.org/' | |
] | |
# threads array | |
threads = [] | |
urls.each do |url| | |
threads << Thread.new(url) do |i| | |
resp = open(i) | |
puts "#{i} has content length #{resp.read.size} symbols" | |
end | |
end | |
# run all threads | |
threads.each { |thr| thr.join } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment