I would like to do some HTTP requests in parallel and return the results as soon as all requests are answered or when a timeout occurs. Looks simple and looking at CPAN Coro + AnyEvent::HTTP (or Coro::LWP) should be the right tools for the job.
Only problem is, I am not at all experienced with event loops and the man pages, including inros, had too many "..." to get me going. So my hope is that one of you friendly Perl Monks has a simple example at hand.
I am hoping for something along these lines:
my @all_results;
foreach my $url (@all_urls) {
http_get $url, sub {
push @all_results, $_[1];
};
}
# but how do I know that all results are there or I run into a timeout
+?
# Where and how comes Coro into the picture?
Many thanks for every help. I just don't get the overall picture and I am sure a tiny example will get me going.
Michael
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.