develooper Front page | perl.perl5.porters | Postings from July 2019

I would love to write: async sub + signatures

Thread Next
Paul "LeoNerd" Evans
July 3, 2019 11:36
I would love to write: async sub + signatures
Message ID:
((A followup to my message
  Subject: Metathread - Programs I would love to write

I would love to write

  use feature 'signatures';
  use Future::AsyncAwait;
  use Future::HTTP;

  async sub get_user_info($uid) {
    my $ua = Future::HTTP->new;
    my $body = await $ua->http_get("$uid");
    return json_decode($body->cobntent);

This would be nice, as it combines two good features:

  * async/await syntax to neaten up asynchronous code and Future-based
    control flow. It looks a lot neater and more readable than the
    previous style of ->then chaining; a subject on which I have
    written at great length[1].

  * subroutine signatures to neaten up the unpacking of arguments
    passed into functions.

However, currently I cannot write this:

  Expected async sub NAME to be followed by '{' at ...

This is due to internal implementation reasons within
Future::AsyncAwait, but before I get into that I want first to
establish the overall theme for this thread; namely that:

  We believe the ability to combine `async sub` with signatures is a
  useful ability to try to achieve.

If we generally agree it'd be nice to be able to write this sort of
thing, then I'll expand more on why it currently doesn't work, why I
believe p5p are the place to begin solving it, and then we can work on
how to fix it.

(There has previously been some discussion on this issue, but it so far
 hasn't gone anywhere:



Paul "LeoNerd" Evans      |  |

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About