Skip to content

Commit

Permalink
Force scalar context for top-level await
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 13, 2021
1 parent 8352ea4 commit 0878ece
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/Promise.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ sub AWAIT_ON_READY {

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

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_deeply [await Mojo::Promise->resolve('works')], ['works'], 'top-level await resolved';
is_deeply [await Mojo::Promise->resolve('just', 'works')], ['just', 'works'], 'top-level await resolved';
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';
eval { await Mojo::Promise->reject('works too') };
like $@, qr/works too/, 'top-level await rejected';

Expand Down

0 comments on commit 0878ece

Please sign in to comment.