Having issues using AnyEvent::DNS with a call back
Robin Redeker
elmex at ta-sa.org
Wed Jun 16 09:45:26 CEST 2010
Hi!
On Wed, Jun 16, 2010 at 12:52:00AM -0400, Michael Greb wrote:
> AnyEvent::DNS docs indicate the following should work, however the script exits 0 nearly instantly with no output:
>
> use AnyEvent::DNS;
> use Data::Dumper;
> my $dns = AnyEvent::DNS->new();
> $dns->resolve( "thegrebs.com", "mx", sub { warn Dumper[@_]} );
You are not running any event loop here. There are only very few operations
with AnyEvent that actually block (and execute a/the event loop). One of them
is the recv() method of a condvar.
> The alternative script below works as expected:
>
> use AnyEvent::DNS;
> use Data::Dumper;
> my $dns = AnyEvent::DNS->new();
> $dns->resolve( "thegrebs.com", "mx", my $cv = AnyEvent->condvar );
> warn Dumper [$cv->recv];
Yep, here $cv->recv blocks until the domain is resolved and returns the result.
If you need a callback try:
$dns->resolve( "thegrebs.com", "mx", my $cv = AnyEvent->condvar );
$cv->cb (sub {
my ($cv) = @_;
warn Dumper [$cv->recv]; # inside the callback recv() doesn't block.
});
Greetings,
Robin
--
Robin Redeker | Deliantra, the free code+content MORPG
elmex at ta-sa.org / r.redeker at gmail.com | http://www.deliantra.net
http://www.ta-sa.org/ |
More information about the anyevent
mailing list