Skip to content

Instantly share code, notes, and snippets.

@ianks
Created June 16, 2017 19:02
Show Gist options
  • Save ianks/0ee3b0d75cd89e56e1663e1060239b2b to your computer and use it in GitHub Desktop.
Save ianks/0ee3b0d75cd89e56e1663e1060239b2b to your computer and use it in GitHub Desktop.
class SomeAPI
def fetch_users
prom = if only_need_to_fetch_one_page?
client.fetch_page(1).then { |res| res.fetch('users') }
else
promises = Concurrent::Promise.zip(client.fetch_page(1), client.fetch_page(2))
promises.then do |first_page, second_page|
combine_results(first_page, second_page)
end
end
prom.value
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment