Created
August 12, 2011 02:11
-
-
Save brikis98/1141291 to your computer and use it in GitHub Desktop.
Example usage of the ASAP library for JRuby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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"]]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Sample output from ASAP example 2 | |
| [["root", | |
| [["root1", | |
| ["child1", "child2", "child3"]], | |
| ["root2", | |
| ["child1", "child2", "child3"]]]]] |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See "Introducing ASAP, an open source parallel assemble JRuby library" for more information.