-
-
Save vbalazs/4d6c85d370f50ea1e8a263b3f7140e51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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