Mixing Coro and AnyEvent makes very little sense in your case.

I have no idea why you say that.

Making a fixed number of HTTP requests in parallel:

use AE qw( ); use AnyEvent::HTTP qw( http_get ); use Coro qw( async ); use Coro::Channel qw( ); sub make_request { my ($url, $cb) = @_; http_get($url, ..., sub { ... $cb->(); }, ); } my $num_workers = 10; my $q = Coro::Channel->new(); my @threads; for (1..$num_workers) { push @threads, async { while (my $url = $q->get()) { my $cv = AE::cv(); make_request($url, $cv); $cv->recv(); } } } while (my $url = get_next_url()) { $q->put($url); } $q->shutdown(); $_->join() for @threads;

Sure, you can do it without Coro too.

use AE qw( ); use AnyEvent::HTTP qw( http_get ); sub make_request { my ($url, $cb) = @_; http_get($url, ..., sub { ... $cb->(); }, ); } my $max_requests = 10; my $active_requests = 0; my $cv = AE::cv(); while (my $url = get_next_url()) { while ($active_requests == $max_requests) { $cv->recv(); $cv = AE::cv(); } ++$active_requests; make_request($url, sub { --$active_requests; $cv->send(); }); } while ($active_requests) { $cv->recv(); $cv = AE::cv(); }

Whatever floats your boat.


In reply to Re^2: Help, AnyEvent::HTTP no work! by ikegami
in thread Help, AnyEvent::HTTP no work! by Perl_Love

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.