parallel http io::lambda
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use lib qw(./lib); | |
use HTTP::Request; | |
use IO::Lambda qw(:lambda); | |
use IO::Lambda::HTTP qw(http_request); | |
use Time::HiRes qw(time); | |
my @urls = ( | |
"https://www.google.com", | |
"http://www.windley.com/", | |
"https://www.bing.com", | |
"http://www.example.com", | |
"http://www.wetpaint.com", | |
"http://www.uh.cu", | |
); | |
my $now = time; | |
sub report | |
{ | |
my ( $response, $url ) = @_; | |
if ( ref($response) and ref($response) eq 'HTTP::Response') { | |
my $url = sprintf "%-25s", $url; | |
my $len = sprintf "%8s", length $response->content; | |
my $et = sprintf "%5.3f", time - $now; | |
print "$url has length $len and loaded in $et ms\n"; | |
$now = time; | |
} else { | |
print "$url has problems: $response\n"; | |
} | |
} | |
lambda { | |
context map { | |
my $url = $_; | |
lambda { | |
context (IO::Lambda::HTTP-> new( HTTP::Request-> new( GET => $url ))); | |
tail { report( shift, $url ) } | |
} | |
} @urls; | |
&tails(); | |
}-> wait; |
This comment has been minimized.
This comment has been minimized.
Neat! I'd never used IO::Lambda before. But I'm getting a problem...
|
This comment has been minimized.
This comment has been minimized.
On Mon, Mar 12, 2012 at 05:47:00PM -0700, Tim Heaney wrote:
Use of uninitialized value $IO::Lambda::HTTP::HTTPS::SSL_ERROR in numeric eq (==) at /home/tim/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2/IO/Lambda/HTTP/HTTPS.pm line 26.
Thanks for the catch! I'm seeing it too, but once in a while, and is quite hard to reproduce. Will work on that
##
Sincerely,
Dmitry Karasik
|
This comment has been minimized.
This comment has been minimized.
fixed, if you're interested check https://github.com/dk/IO-Lambda |
This comment has been minimized.
This comment has been minimized.
Works great! I downloaded it from here with
and then added use lib "$ENV{HOME}/IO-Lambda/lib"; to my script. Have you uploaded it to CPAN?
Perhaps you did and just forgot to up the version number? |
This comment has been minimized.
This comment has been minimized.
Hi Tim,
Not yet, I usually wait for some more bugs to accumulate before I release
a new version ... but this time I'll do it now. Thanks a lot for the test!
/dk
On Wed, Mar 14, 2012 at 05:17:58PM -0700, Tim Heaney wrote:
Works great! I downloaded it from here with
```
git clone https://github.com/dk/IO-Lambda.git
```
and then added
``` perl
use lib "$ENV{HOME}/IO-Lambda/lib";
```
to my script. Have you uploaded it to CPAN?
```
$ cpanm IO::Lambda
IO::Lambda is up to date. (1.22)
```
Perhaps you did and just forgot to up the version number?
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2021875
##
Sincerely,
Dmitry Karasik
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
https://www.bing.com has length 216 and loaded in 0.048 ms
http://www.wetpaint.com has length 4648 and loaded in 0.341 ms
https://www.google.com has length 31651 and loaded in 0.147 ms
http://www.example.com has length 2966 and loaded in 0.172 ms
http://www.windley.com/ has length 83905 and loaded in 0.313 ms
http://www.uh.cu has length 18454 and loaded in 2.415 ms