-
-
Save mishin/6449658 to your computer and use it in GitHub Desktop.
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
# Alternate implementation of https://metacpan.org/module/STEVAN/Promises-0.03/lib/Promises/Cookbook/TIMTOWTDI.pod | |
# that can run the requests in parallel | |
# See also a more concrete application of this: https://gist.github.com/dolmen/6306377 | |
my $all_product_info = {}; | |
my $cv = AnyEvent->condvar; | |
$cv->begin; | |
http_get('http://rest.api.example.com/-/product/12345', sub { | |
my ($product) = @_; | |
$all_product_info->{product} = $product; | |
$cv->end; | |
}); | |
$cv->begin; | |
http_get('http://rest.api.example.com/-/product/suggestions?for_sku=12345', sub { | |
my ($suggestions) = @_; | |
$all_product_info->{suggestions} = $suggestions; | |
$cv->end; | |
}); | |
$cv->begin; | |
http_get('http://rest.api.example.com/-/product/reviews?for_sku=12345', sub { | |
my ($reviews) = @_; | |
$all_product_info->{reviews} = $reviews; | |
$cv->end; | |
}), | |
$cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment