AnyEvent-Future
view release on metacpan or search on metacpan
Build.PL
Changes
examples/http_get.pl
lib/AnyEvent/Future.pm
MANIFEST This list of files
t/00use.t
t/01anyevent.t
t/02timer.t
t/03condvar.t
t/99pod.t
README
LICENSE
META.yml
META.json
new_delay
$f = AnyEvent::Future->new_delay( @args )
new_timeout
$f = AnyEvent::Future->new_timeout( @args )
Returns a new leaf future instance that will become ready at the time
given by the arguments, which will be passed to the AnyEvent->timer
method.
new_delay returns a future that will complete successfully at the
alotted time, whereas new_timeout returns a future that will fail with
the message Timeout. This is provided as a simple utility for small
use-cases; for a more find-grained control over the failure message and
additional values you may wish to use new_delay combined with the
then_fail method:
new_delay( after => 10 )
lib/AnyEvent/Future.pm view on Meta::CPAN
=head2 new_delay
$f = AnyEvent::Future->new_delay( @args )
=head2 new_timeout
$f = AnyEvent::Future->new_timeout( @args )
Returns a new leaf future instance that will become ready at the time given by
the arguments, which will be passed to the C<< AnyEvent->timer >> method.
C<new_delay> returns a future that will complete successfully at the alotted
time, whereas C<new_timeout> returns a future that will fail with the message
C<Timeout>. This is provided as a simple utility for small use-cases; for a
more find-grained control over the failure message and additional values you
may wish to use C<new_delay> combined with the C<then_fail> method:
new_delay( after => 10 )
->then_fail( "The operation timed out after 10 seconds", timeout => );
=cut
sub new_delay
{
shift;
my %args = @_;
as_future {
my $f = shift;
AnyEvent->timer( %args, cb => sub { $f->done } );
};
}
sub new_timeout
{
shift;
my %args = @_;
as_future {
my $f = shift;
AnyEvent->timer( %args, cb => sub { $f->fail( "Timeout" ) } );
};
}
=head2 from_cv
$f = AnyEvent::Future->from_cv( $cv )
Returns a new leaf future instance that will become ready when the given
L<AnyEvent::CondVar> instance is ready. The success or failure result of the
future will be the result passed to the condvar's C<send> or C<croak> method.
t/01anyevent.t view on Meta::CPAN
};
is_deeply( [ $future->get ], [ "another result" ], '$future->get on as_future' );
}
# as_future cancellation
{
my $called;
my $future = as_future {
my $f = shift;
return AnyEvent->timer(
after => 0.01,
cb => sub { $called++; $f->done; },
);
};
$future->cancel;
my $cv = AnyEvent->condvar;
my $tmp = AnyEvent->timer( after => 0.03, cb => sub { $cv->send } );
$cv->recv;
ok( !$called, '$future->cancel cancels a pending watch' );
}
# as_future_cb done
{
my $future = as_future_cb {
my ( $done ) = @_;
AnyEvent::postpone { $done->( "success" ) };
( run in 2.658 seconds using v1.01-cache-2.11-cpan-49f99fa48dc )