ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/lwp
(Generate patch)

Comparing Coro/eg/lwp (file contents):
Revision 1.4 by root, Sun Nov 5 02:01:24 2006 UTC vs.
Revision 1.9 by root, Mon Nov 24 07:55:28 2008 UTC

1#!/usr/bin/perl 1#!/usr/bin/perl
2 2
3# this hack shows how one can get LWP to be less blocking. 3use Coro::LWP; # should be use'd as early as possible
4
5{
6 # we replace Socket::inet_aton and CORE::select
7 use Coro::Select; # must come early
8 use Coro::Util;
9 use Coro::Socket;
10 use IO::Socket::INET;
11 use Socket;
12 BEGIN {
13 *Socket::inet_aton = \&Coro::Util::inet_aton;
14 *IO::Socket::INET::new = sub { new Coro::Socket forward_class => @_ };
15 }
16}
17 4
18use Coro; 5use Coro;
19use Coro::Event; 6use Coro::AnyEvent;
20use LWP::Simple; 7use LWP::Simple;
21 8
22$SIG{PIPE} = 'IGNORE'; 9$SIG{PIPE} = 'IGNORE';
23 10
24async { 11my @pids;
25 print "hi2\n";
26 get "http://www.google.de/";
27 print "ho2\n";
28};
29 12
30async { 13for (1..1) {
31 print "hi\n"; 14 push @pid, async {
15 print "starting to fetch http://www.google.de/\n";
32 get "http://www.yahoo.com/"; 16 get "http://www.google.de/";
33 print "ho\n"; 17 print "fetched http://www.google.de/\n";
18 };
34 19
35}; 20 push @pid, async {
21 print "starting to fetch http://www.yahoo.com/\n";
22 get "http://www.yahoo.com/";
23 print "fetched http://www.yahoo.com/\n";
24 };
25}
36 26
37loop; 27$_->join for @pid;
38 28

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines