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 hidden or 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; |
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
fixed, if you're interested check https://github.com/dk/IO-Lambda