Mark Martinec writes:
> > Almost. One of the biggest problems I see is that one can't register a
> > socket with AsyncLoop.pm. Thereby, when DNS lookups are finished, the whole
> > loop stops regardless of outstanding non-DNS-based lookups.
> >
> > See sub complete_lookups in AsyncLoop.pm:
> >     my $nfound = $self->{main}->{resolver}->poll_responses($timeout);
> >     $nfound ||= 'no';
> >     dbg ("async: select found $nfound socks ready");
> >     foreach my $key (keys %{$pending}) {
> >       my $ent = $pending->{$key};
> >
> > poll_responsens is in DnsResolver.pm and yield 0 when DNS queries are
> > finished. This causes the complete_lookups call to terminate all the
> > outstanding lookups, even the non-DNS-based ones.
> 
> Not really (at least not in the current trunk I'm looking at).
> As long as there are any (non timed-out) requests in %$pending,
> it does not terminate, even if poll returns empty-handed.
> And 'a request' is a rather general term. Currently it covers
> DNS requests, but in principle could be other kind of 'requests'.
> There are routines for submitting and terminating requests.
> 
> I'd be interested too if more general usage emerges, perhaps
> along with a somewhat cleaned/generalized API.  My wish is
> to provide a mechanism for Plugins (such as DKIM, SPF, Razor2)
> to use the same async services and avoid doing their network
> lookups synchronously on their own. Suggestions welcome.

+1 agreed.

> If only Perl could have a way of expressing co-routines,
> then one could build a simple task scheduler, with task queues
> on blocked resources, etc.

Bear in mind that perl's extremely flexible closure support
is a great help here.  e.g. you can write

    sub start_request {
      my $request = ...;
      my $foo = ...;
      my $bar = do_something();

      call_back_once_complete ($request, sub {      # line A

        proc_response($foo, $bar);

      });
    }

in other words the closure can act as a kind of "second half" coroutine;
it helps if you think of line A as a "yield" statement ;)
I'm sure there are clean patterns around to express this... also I
know Matt Sergeant spent some time looking into it.

> > Does anybody knows which is the API to the async stuff? Maybe
> > I didn't  get it at all and I'm attempting to use it the wrong way...
> 
> Not much docs about API, but see comments on subroutines in
> AsyncLoop.pm, and their typical usage by Dns.pm.

Also there's some usage by bundled plugins in lib/Mail/SpamAssassin/Plugin/.

--j.

Reply via email to