Skip to content

Instantly share code, notes, and snippets.

@richievos
Created April 28, 2012 15:36
Show Gist options
  • Save richievos/2519851 to your computer and use it in GitHub Desktop.
Save richievos/2519851 to your computer and use it in GitHub Desktop.
# when we can, we do something like this:
in_parallel do |hydra|
hydra.push client.get_x(:user_id => 1, :id => 2) do |response|
@x = response.processed_response if response.success?
end
hydra.push client.get_y(:user_id => 1, :id => 3) do |response|
@y = response.processed_response if response.success?
end
end # at the end of the block it fires the requests in parallel and ... blocks
# when there's a single request, or the usage is explicitly serial, we do something like this
# unlike the above, fire! raises an exception if the request fails
@z = fire!(client.get_z(:user_id => 1, :id => 4))
# we also have a version without a ! which doesn't raise an exception
@a = fire(client.get_z(:user_id => 1, :id => 4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment