AnyEvent-Promise
view release on metacpan or search on metacpan
lib/AnyEvent/Promise.pm view on Meta::CPAN
})->then(sub {
say shift;
})->catch(sub {
say 'I failed!';
say @_;
})->fulfill;
=head1 DESCRIPTION
L<AnyEvent::Promise> allows evented interfaces to be chained, taking away some
of the redundancy of layering L<AnyEvent> condition variable callbacks.
A promise is created using L<AnyEvent::Promise::new|/new> or the exported
L</promise> helper function. These will both return a promise instance and add
the callback function as the start of the promise chain. Each call to L</then>
on the promise instance will add another subroutine which returns a condition
variable to the chain.
The promise callback chain won't start until L</condvar> or L</fulfill> is
called on the instance. Calling L</condvar> or L</cv> will start the callback
chain and return the promise guarding condvar, which is fulfilled after the last
callback on the chain returns. Similarily, L</fulfill> will start the chain, but
will block until the guarding condvar is fulfilled.
Errors in the callbacks can be caught by setting an exception handler via the
L</catch> method on the promise instance. This method will catch exceptions
raised from L<AnyEvent> objects and exceptions raised in blocks provided to
L</then>. If an error is encountered in the chain, an exception will be thrown
and the rest of the chain will be skipped, jumping straight to the catch
callback.
=head1 EXPORT
=head2 promise($cb)
lib/AnyEvent/Promise.pm view on Meta::CPAN
}
});
$self->{fulfill} = $cvout;
return $self;
}
=head2 catch($cb)
Catch raised errors in the callback chain. Exceptions in the promise chain will
jump up to this catch callback, bypassing any other callbacks in the promise
chain. The error caught by L<Try::Tiny> will be sent as arguments to the
callback C<$cb>.
=cut
sub catch {
my ($self, $fn) = @_;
$self->{reject}->cb(sub {
my @err = shift->recv;
$fn->(@err);
( run in 0.727 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )