Created
March 12, 2012 13:21
-
-
Save dk/2021875 to your computer and use it in GitHub Desktop.
parallel http io::lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
Neat! I'd never used IO::Lambda before. But I'm getting a problem...
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.
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 35.
https://www.google.com has problems: ssl
https://www.bing.com has length 216 and loaded in 1.141 ms
http://www.example.com has length 2966 and loaded in 0.146 ms
http://www.windley.com/ has length 83896 and loaded in 0.450 ms
http://www.wetpaint.com has length 1056 and loaded in 0.376 ms
http://www.uh.cu has length 18518 and loaded in 4.679 ms
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
fixed, if you're interested check https://github.com/dk/IO-Lambda
Works great! I downloaded it from here with
git clone https://github.com/dk/IO-Lambda.git
and then added
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?
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
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