Making multiple HTTP requests asynchronously
问题 require 'net/http' urls = [ {'link' => 'http://www.google.com/'}, {'link' => 'http://www.yandex.ru/'}, {'link' => 'http://www.baidu.com/'} ] urls.each do |u| u['content'] = Net::HTTP.get( URI.parse(u['link']) ) end print urls This code works in synchronous style. First request, second, third. I would like to send all requests asynchronously and print urls after all of them is done. What the best way to do it? Is Fiber suited for that? 回答1: Here's an example using threads. require 'net/http'