Slide 12
Slide 12 text
© 2014 DataStax, All Rights Reserved.
Future Composition
12
select_user = session.prepare("SELECT * FROM users WHERE id = ?")
select_page = session.prepare("SELECT * FROM pages WHERE slug = ?")
user_ids = [1, 2, 3, 4]
futures = user_ids.map do |id|
future = session.execute_async(select_user, id)
future.then do |users|
user = users.first
future = session.execute_async(select_page, user[‘username'])
future.then do |pages|
page = pages.first
User.new(user, Page.new(page))
end
end
end
Cassandra::Future.all(futures).get