AnyEvent-Future

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

 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 )
          ->then_fail( "The operation timed out after 10 seconds", timeout => );

 from_cv

       $f = AnyEvent::Future->from_cv( $cv )

lib/AnyEvent/Future.pm  view on Meta::CPAN


=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
{

lib/AnyEvent/Future.pm  view on Meta::CPAN

   };
}

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/02timer.t  view on Meta::CPAN

   is_deeply( [ $future->get ], [], '$future->get returns empty list on new_delay' );
}

# new_timeout
{
   my $future = AnyEvent::Future->new_timeout( after => 1 );

   time_about( sub { $future->await }, 1, '->new_timeout is ready' );

   ok( $future->is_ready, '$future is ready from new_timeout' );
   is( $future->failure, "Timeout", '$future failed with "Timeout" for new_timeout' );
}

done_testing;



( run in 0.257 second using v1.01-cache-2.11-cpan-a5abf4f5562 )