Skip to content

Instantly share code, notes, and snippets.

@brikis98
Created August 12, 2011 02:11
Show Gist options
  • Select an option

  • Save brikis98/1141291 to your computer and use it in GitHub Desktop.

Select an option

Save brikis98/1141291 to your computer and use it in GitHub Desktop.
Example usage of the ASAP library for JRuby
# ASAP example 1: fetch a list of users and then for each user, fetch their data in parallel
# For simplicity, the format of data returned by our "services" are just CSV strings
data = Asap do
get "http://url/to/user/list" do |users|
# this block of code does not execute until the above request is completed
list = users.split(", ")
list.each do |user|
# all of these will execute in parallel
get "http://url/to/#{user}/data"
end
end
end
# Sample output from ASAP example 1
# The data format matches the dependency tree structure
[["user_id_1, user_id_2, user_id3",
["user_data_1", "user_data_2", "user_data_3"]]]
# ASAP example 2: shows more complicated nesting and parallelism
data = Asap do
get "http://root/" do |root|
get "#{root}1" do |child|
get "#{child}1"
get "#{child}2"
get "#{child}3"
end
get "#{root}2" do |child|
get "#{child}1"
get "#{child}2"
get "#{child}3"
end
end
end
# Sample output from ASAP example 2
[["root",
[["root1",
["child1", "child2", "child3"]],
["root2",
["child1", "child2", "child3"]]]]]
@brikis98
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment