require \'net/http\'
urls = [
{\'link\' => \'http://www.google.com/\'},
{\'link\' => \'http://www.yandex.ru/\'},
{\'link\' => \'http://www.baidu.com/\'}
]
ur
The work_queue gem is the easiest way to perform tasks asynchronously and concurrently in your application.
wq = WorkQueue.new 2 # Limit the maximum number of simultaneous worker threads
urls.each do |url|
wq.enqueue_b do
response = Net::HTTP.get_response(url)
# use the response
end
end
wq.join # All requests are complete after this