Skip to content

Commit

Permalink
Reuse AWAIT_GET for AWAIT_WAIT
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 13, 2021
1 parent 0878ece commit 29fc0f3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/Mojo/Promise.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ sub AWAIT_ON_READY {

sub AWAIT_WAIT {
my $self = shift;
my ($result, $error);
$self->then(sub { $result = shift }, sub { $error = shift })->wait;
return defined $error ? die $error : $result;
$self->catch(sub { })->wait;
return $self->AWAIT_GET;
}

sub DESTROY {
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/promise_async_await.t
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ subtest 'Async WebSocket' => sub {
};

# Top-level await
is await Mojo::Promise->resolve('works'), 'works', 'top-level await resolved';
is await Mojo::Promise->resolve('just works', 'fails'), 'just works', 'top-level await resolved';
is scalar await Mojo::Promise->resolve('works'), 'works', 'top-level await resolved';
is_deeply [await Mojo::Promise->resolve('just', 'works')], ['just', 'works'], 'top-level await resolved';
eval { await Mojo::Promise->reject('works too') };
like $@, qr/works too/, 'top-level await rejected';

Expand Down

0 comments on commit 29fc0f3

Please sign in to comment.