Subject: | shut down PoCo::Client::HTTP for prompt program exit |
Hi, Mike!
Changes to the POE::Component::Client::HTTP stack require an explicit shutdown to allow a prompt
program exit. Here's a small test case someone brought to my attention in IRC. Some notes:
1. Without the "tick" timer, the session exits before a response can arrive.
2. Without the "shutdown" in _stop, the program will linger until sockets and resolvers time out in
POE::Component::KeepAlive and POE::Component::Resolver, respectively.
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent::POE;
use POE;
my $ua = LWP::UserAgent::POE->new();
POE::Session->create(
inline_states => {
_start => sub {
$_[KERNEL]->delay(tick => 1); # turn it on
test_get();
$_[KERNEL]->delay(tick => undef); # turn it off
},
tick => sub {
print "asynchronous timers working...\n";
$_[KERNEL]->delay(tick => 1); # repeat while we're here
},
_stop => sub {
# When we stop, shut down the UA's internal PoCo::Client::HTTP.
# It doesn't seem to do that itself, which is probably a bug.
# This is done with call() because messages post()ed from _stop
# won't be dispatched to their destinations.
$_[KERNEL]->call( $ua->{poco_alias}, "shutdown" );
},
},
);
POE::Kernel->run();
sub test_get
{
print "hello, world\n";
my $resp = $ua->get("http://www.yahoo.com/");
print $resp->content, "\n";
}