I have a WWW::Mechanize object logged into a company intranet page and I'm trying to download the org chart. I start at the CEO and work down until all the users are seen.
To get the info for 1 user three http requests are made and I'm trying to have them done asynchronously.
Below is a contrived example of what I'm trying to do and I boiled it down to this.
Why would these three events not be running in parallel? How can I get them to run in parallel? Thanks
#!/usr/bin/perl
use Modern::Perl;
use AnyEvent;
my @users = ( 1 );
while ( @users ) {
my $user_id = shift @users;
my ( $info_1, $info_2, $info_3 );
my $cv = AnyEvent->condvar;
# get the first user info
$cv->begin;
say "request 1";
$info_1 = "x";
sleep 10;
$cv->end;
# get the second user info
$cv->begin;
say "request 2";
$info_2 = "x";
sleep 10;
$cv->end;
# get the second user info
$cv->begin;
say "request 3";
$info_3 = "x";
sleep 10;
$cv->end;
# merge pont
$cv->recv;
say "$user_id: $info_1, $info_2, $info_3";
}
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.