Skip to content

Instantly share code, notes, and snippets.

@kopylovvlad
Created October 12, 2018 18:53
Show Gist options
  • Save kopylovvlad/0b400e74853defbebe0c1a6ef7b25969 to your computer and use it in GitHub Desktop.
Save kopylovvlad/0b400e74853defbebe0c1a6ef7b25969 to your computer and use it in GitHub Desktop.
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