Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'em-http'
def download_em_http(urls, concurrency)
EventMachine.run do
multi = EventMachine::MultiRequest.new
EM::Iterator.new(urls, concurrency).each do |url, iterator|
req = EventMachine::HttpRequest.new(url).get
req.callback do
write_file url, req.response
iterator.next
end
multi.add url, req
multi.callback { EventMachine.stop } if url == urls.last
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.