Slide 25
Slide 25 text
© 2015 DataStax, All Rights Reserved.
Future Composition
19
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, arguments: [id])
future.then do |users|
user = users.first
future = session.execute_async(select_page, arguments: [user['username']])
future.then do |pages|
page = pages.first
User.new(user, Page.new(page))
end
end
end
Cassandra::Future.all(futures).get