Created
August 22, 2013 14:40
-
-
Save dolmen/6308088 to your computer and use it in GitHub Desktop.
Fix for Promises::Cookbook::TIMTOWTDI
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