Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.