Skip to content

Instantly share code, notes, and snippets.

@vbalazs
Created April 22, 2018 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbalazs/4d6c85d370f50ea1e8a263b3f7140e51 to your computer and use it in GitHub Desktop.
Save vbalazs/4d6c85d370f50ea1e8a263b3f7140e51 to your computer and use it in GitHub Desktop.
def call(agent:, pages: 10, filter: nil)
jobs = 1.upto(pages).map do |n|
Concurrent::Promise.execute do
beers = fetch_page(n)
new_elements = filter.is_a?(Proc) ? beers.select(&filter) : beers
agent.send { |set| set | new_elements }
end
end
jobs.map(&:value)
agent.await.value
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment