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

Re: async/await syntax - overview

Thread Previous
Josh Juran
July 2, 2016 07:50
Re: async/await syntax - overview
Message ID:
On Jul 1, 2016, at 5:15 PM, "Paul \"LeoNerd\" Evans" <> wrote:

> That these three thematically-distinct languages have all converged on
> basically the same syntax and semantics suggests to me this is a nice
> design, and one I would like to replicate in Perl 5.

For the programming language I'm developing (among whose inspirations is Perl), I've opted against it.  In "V", `async` is a builtin function that takes a subroutine argument, starts a thread that calls the subroutine, and returns a future.  The future object has pointer semantics, and dereferencing it (using left unary `*`, as in C) joins the thread and returns the result) or throws the exception).

    var tbd_foo = async { sha256 foo() };  # starts a thread
    var tbd_bar = async { sha256 bar() };  # starts another thread
    # Both hash operations run currently, CPU permitting
    print( "foo: ", *tbd_foo, "bar: ", *tbd_bar );  # blocks until the other threads complete

(I have a proof-of-concept branch for async(), but it's incomplete and hasn't been published.)

The V Programming Language

It's possible I've missed something about async/await, but compared to multithreading, it seems both less useful and harder to understand.  Anyway, that's my opinion.


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