Skip Menu |
 

This queue is for tickets about the Future-AsyncAwait CPAN distribution.

Report information
The Basics
Id: 122823
Status: new
Priority: 0/
Queue: Future-AsyncAwait

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Support 'await' defaulting on $_
The-attached patch by Ilmari -- Paul Evans
Subject: await-default-dollarsmudge.patch
commit 4028ae238676771d7368eb828af68cb05c6c90be Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> Date: 2017-08-11 16:43:09 +0200 Make await with no argument use $_ diff --git a/lib/Future/AsyncAwait.pm b/lib/Future/AsyncAwait.pm index d1c5c17..ea9c34f 100644 --- a/lib/Future/AsyncAwait.pm +++ b/lib/Future/AsyncAwait.pm @@ -73,8 +73,9 @@ returned future to fail. =head2 C<await> -The C<await> keyword forms an expression which takes a C<Future> instance as -an operand and yields the eventual result of it. Superficially it can be +The C<await> keyword forms an expression which takes a C<Future> +instance as an operand and yields the eventual result of it. If the +operand expression is omitted, C<$_> is used. Superficially it can be thought of similar to invoking the C<get> method on the future. my $result = await $f; diff --git a/lib/Future/AsyncAwait.xs b/lib/Future/AsyncAwait.xs index 2c698df..97edc50 100644 --- a/lib/Future/AsyncAwait.xs +++ b/lib/Future/AsyncAwait.xs @@ -850,8 +850,11 @@ static int await_keyword_plugin(pTHX_ OP **op_ptr) croak("Expected ')'"); lex_read_unichar(0); } - else - expr = parse_termexpr(0); + else { + expr = parse_termexpr(PARSE_OPTIONAL); + if (!expr) + expr = newDEFSVOP(); + } *op_ptr = newAWAITOP(0, expr); diff --git a/t/03await.t b/t/03await.t index 78d7590..a6c0728 100644 --- a/t/03await.t +++ b/t/03await.t @@ -101,4 +101,17 @@ async sub makelist is( scalar $fret->get, "later", '$fret->get for ANON closure' ); } +{ + async sub await_defsv { + $_ = shift; + await; + } + + my $f1 = Future->new; + my $fret = await_defsv($f1); + + $f1->done("defsv"); + is( scalar $fret->get, "defsv", 'no-arg await uses $_' ); +} + done_testing;
Download (untitled) / with headers
text/plain 395b
Before applying this though it's worth considering whether this would close off any other syntax tricks we may want to perform with 'await' elsewhere. I've been reserving 'async' not followed by 'sub' for a possible consideration around concurrent map/grep/similar by using a syntax like async grep { ... } LIST but as yet I have no firm thoughts on other uses for 'await'. -- Paul Evans


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.