Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'async'
require 'async/barrier'
require 'open-uri'
def async_fetch(*urls)
barrier = Async::Barrier.new
Async do
urls.map do |url|
barrier.async { URI.open url, &:read }
end.tap { barrier.wait }
end.result.map(&:result)
end
url = 'https://api.kanye.rest?format=text'
puts async_fetch url, url, url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment