Last active
May 20, 2018 23:08
-
-
Save veganstraightedge/7873b2dc905e9fe08c115447d6217a70 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
promises = [] | |
# Create the collection of promises to do | |
(1..10).each do |i| | |
promises << Concurrent::Promise.execute do | |
thing = get the thing from the API | |
Thing.create! name: thing.name | |
end | |
end | |
# Do the work in all of the promises: get a thing, save it to the database | |
promises.map { |p| p.wait } | |
puts "Things now in the database: #{Thing.count}" | |
# => 4 | |
# I EXPECT THAT TO BE 10! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment