AE-AdHoc
view release on metacpan or search on metacpan
0.04 Sun Sep 09 2012
* API: Add arglist support to callbacks: ae_recv { ae_send->(1..5) };
* API: Add extra arguments to callback: ae_recv { ae_send(1..5) };
* Example added (port-probe.pl)
0.03 Thu Sep 06 2012
* API: Make empty/zero $timeout illegal.
0.0203 Tue Aug 14 2012
* Fixed empty $timeout undef warning.
* Minor code cleanup.
0.02 Sat Aug 11 2012
First version, released on an unsuspecting world.
- ae_recv, ae_send and ae_croak wotk and pass most basic tests
lib/AE/AdHoc.pm view on Meta::CPAN
# set up event loop
my $cv = AnyEvent->condvar;
my $timer = AnyEvent->timer(
after => 10, cb => sub { $cv->croak("Timeout"); }
);
do_stuff( @args, sub{ $cv->send(shift); } );
# run event loop, get rid of timer
my $result = $cv->recv();
undef $timer;
# finally
analyze_results( $result );
Now, the same with AE::AdHoc:
use AE::AdHoc;
my $result = ae_recv {
do_stuff( @args, ae_send );
lib/AE/AdHoc.pm view on Meta::CPAN
$timeout must be a nonzero real number. Negative value means "run forever".
$timeout=0 would be ambigous, so it's excluded.
Options may include:
=over
=item * timeout - override the $timeout parameter (one timeout MUST be present).
=item * soft_timeout - Override $timeout, and don't die,
but return undef instead.
=back
Other functions in this module would die if called outside of C<ae_recv>.
=cut
# $cv is our so that it can be localized and act as a lock
our $cv;
lib/AE/AdHoc.pm view on Meta::CPAN
$opt{after} ||= 0;
my $count = $opt{count};
my $inf = !$count;
my $n = 0;
my $timer;
my $cb = sub {
if (!$cv) {
undef $timer;
return _error( "Leftover $exact called outside ae_recv" );
};
$myiter == $iter or undef $timer;
$inf or $count-->0 or undef $timer;
$timer and $code->($n++);
};
$timer = AnyEvent->timer(
after=>$opt{after}, interval=>$opt{interval}, cb=>$cb);
return;
};
=head1 ERROR HANDLING
Dying within event loop is a bad idea, so we issue B<warnings> and write
( run in 1.449 second using v1.01-cache-2.11-cpan-d80b1682f3f )