Having issues using AnyEvent::DNS with a call back

Robin Redeker elmex at ta-sa.org
Wed Jun 16 19:13:05 CEST 2010


Hi!

On Wed, Jun 16, 2010 at 09:13:20AM -0400, Michael Greb wrote:
> > 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.
> >   });
> 
> Well, there's the real problem ;) I see the same failed behavior with this,
> the script exits 0 almost immediately with no output. AnyEvent version on
> 5.271 the Apple supplied Perl 5.10.0 as well as on the Debian Lenny supplied
> Perl 5.10.0 and Debian Sid Perl 5.10.1.

Oh, well, I made a mistake there myself. There still needs to be something
blocking until something is done. Like for instance a second condvar
or an explicit call to an event loop. Setting cb() will not change the
behaviour.

So try something like this:

   $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.
   });

   $cv->recv;


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