Created
June 16, 2017 19:02
-
-
Save ianks/0ee3b0d75cd89e56e1663e1060239b2b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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