Skip to content

Commit

Permalink
fix a bug in Mojo::Promise where chains could not recover from reject…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
kraih committed Nov 4, 2017
1 parent e6b17ae commit b09d55a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,5 +1,7 @@

7.54 2017-11-05
- Fixed a bug in Mojo::Promise where promise chains could not recover from
rejections.

7.53 2017-11-04
- Added module Mojo::Promise.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Promise.pm
Expand Up @@ -111,7 +111,7 @@ sub _then {
my @res;
return $new->reject($@) unless eval { @res = $cb->(@result); 1 };

return $new->$method(@res)
return $new->resolve(@res)
unless @res == 1 && blessed $res[0] && $res[0]->can('then');

$res[0]->then(sub { $new->resolve(@_); () }, sub { $new->reject(@_); () });
Expand Down
5 changes: 3 additions & 2 deletions t/mojo/promise.t
Expand Up @@ -79,8 +79,9 @@ is_deeply \@results, ['test:1:2:3:4'], 'promises resolved';
# Rejected chained
$promise = Mojo::Promise->new;
@errors = ();
$promise->then(undef, sub {"$_[0]:1"})->then(undef, sub {"$_[0]:2"})
->then(undef, sub {"$_[0]:3"})->then(undef, sub { push @errors, "$_[0]:4" });
$promise->then(undef, sub {"$_[0]:1"})
->then(sub {"$_[0]:2"}, sub {"$_[0]:fail"})->then(sub {"$_[0]:3"})
->then(sub { push @errors, "$_[0]:4" });
$promise->reject('tset');
Mojo::IOLoop->one_tick;
is_deeply \@errors, ['tset:1:2:3:4'], 'promises rejected';
Expand Down

0 comments on commit b09d55a

Please sign in to comment.