AE-AdHoc
view release on metacpan or search on metacpan
lib/AE/AdHoc.pm view on Meta::CPAN
B<Note>: Anywhere below, C<$cv> means L<AnyEvent>'s conditional variable
responsible for current event loop. See C<condvar> section of L<AnyEvent>.
=cut
our $VERSION = '0.0805';
use Carp;
use AnyEvent::Strict;
use Scalar::Util qw(weaken looks_like_number);
use Exporter;
BEGIN {
our @ISA = qw(Exporter);
our @EXPORT = qw(ae_recv ae_send ae_croak ae_begin ae_end ae_goal ae_action);
};
=head2 ae_recv { CODE; } [ $timeout ] %options;
lib/AE/AdHoc.pm view on Meta::CPAN
my $timeout = @_ % 2 && shift; # load bare timeout if present
my %opt = @_;
$timeout = $opt{timeout} || $opt{soft_timeout} || $timeout;
# check we're not in event loop before dying
$cv and _croak("Nested calls to ae_recv are not allowed");
local $cv = AnyEvent->condvar;
croak "Parameter timeout must be a nonzero real number"
if (!$timeout or !looks_like_number($timeout));
# find out where we are
$iter++;
my @caller = caller(0);
local $where = "ae_recv[$iter] at $caller[1]:$caller[2]";
my $on_timeout = $opt{soft_timeout}
? sub { $cv->send }
: sub { $cv->croak("Timeout after $timeout seconds"); };
my $timer;
( run in 0.508 second using v1.01-cache-2.11-cpan-64827b87656 )