Skip to content

Commit

Permalink
catch exceptions in callbacks and act accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevan Little committed Oct 22, 2013
1 parent bf7382a commit d78f2f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Revision history for Perl extension Promises

0.05
- catch exceptions in any callback and
call reject if they happen

0.04 Thursday, Oct. 17, 2013
*** DEPRECATION WARNING ***
- The 'when' helper in Promises.pm is being
Expand Down
7 changes: 5 additions & 2 deletions lib/Promises/Deferred.pm
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ sub then {
sub _wrap {
my ($self, $d, $f, $method) = @_;
return sub {
my @results = $f->( @_ );
if ( (scalar @results) == 1 && blessed $results[0] && $results[0]->isa('Promises::Promise') ) {
local $@;
my @results = do { $f->( @_ ) };
if ($@) {
$d->reject( $@ );
} elsif ( (scalar @results) == 1 && blessed $results[0] && $results[0]->isa('Promises::Promise') ) {
$results[0]->then(
sub { $d->resolve( @{ $results[0]->result } ) },
sub { $d->reject( @{ $results[0]->result } ) },
Expand Down

0 comments on commit d78f2f4

Please sign in to comment.