--- Coro/eg/lwp 2001/09/03 02:50:18 1.3 +++ Coro/eg/lwp 2008/11/24 04:56:38 1.8 @@ -1,35 +1,27 @@ #!/usr/bin/perl -# this hack shows how one can overwrite IO::Socket::INET to provide -# non-blocking sockets by default. This makes lwp magically -# non-blocking. I hope. - -{ - # this is all the required magic: we replace the constructor. - use Coro::Socket; - use IO::Socket::INET; - sub IO::Socket::INET::new { - shift; new Coro::Socket @_; - }; -} - use Coro; -use Coro::Event; +use Coro::AnyEvent; +use Coro::LWP; # should be use'd as early as possible use LWP::Simple; $SIG{PIPE} = 'IGNORE'; -async { - print "hi\n"; - get "http://localhost/"; - print "ho\n"; - -}; - -async { - print "hi2\n"; - get "http://localhost/"; - print "ho2\n"; -}; +my @pids; + +for (1..1) { + push @pid, async { + print "starting to fetch http://www.google.de/\n"; + get "http://www.google.de/"; + print "fetched http://www.google.de/\n"; + }; + + push @pid, async { + print "starting to fetch http://www.yahoo.com/\n"; + get "http://www.yahoo.com/"; + print "fetched http://www.yahoo.com/\n"; + }; +} + +$_->join for @pid; -loop;