in reply to Help, AnyEvent::HTTP no work!

The easy approach is to read the documentation of AnyEvent::HTTP again. It documents your error situation and the remedy in detail because it's a very common error. Also, mixing Coro and AnyEvent makes very little sense in your case. Your code is IO/network-bound and won't benefit from the additional paralelization possibility that Coro opens up for you.

Also note that writing a password cracker is not really a great use of your and our time, and might even be illegal depending on your jurisdiction.

Replies are listed 'Best First'.
Re^2: Help, AnyEvent::HTTP no work!
by ikegami (Patriarch) on May 09, 2016 at 16:19 UTC

    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.