Skip to content

Instantly share code, notes, and snippets.

@dbalatero
Forked from pauldix/gist:176464
Created August 27, 2009 18:43
Show Gist options
  • Save dbalatero/176469 to your computer and use it in GitHub Desktop.
Save dbalatero/176469 to your computer and use it in GitHub Desktop.
hydra = Typhoeus::Hydra.new(20) # number is the size of the easy object pool
user_request = User.find_request(1) # where 1 is the id of the user
user_request.on_complete do
@user = User.parse(user_request.response.body)
comment_requests = @user.comment_ids.map {|id| Comment.find_request(id)}
comment_requests.each do |comment_request|
comment_request.on_complete do
@user.comments << Comment.parse(comment_request.response.body)
end
hydra.queue << comment_request
end
end
hydra.queue << user_request
hydra.run!
# now we have a user object with all the comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment