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

Re: async/await syntax - overview

Thread Previous
From:
Josh Juran
Date:
July 2, 2016 07:50
Subject:
Re: async/await syntax - overview
Message ID:
CED5DFA6-9CE0-41B1-ABA1-B2679E291617@gmail.com
On Jul 1, 2016, at 5:15 PM, "Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> 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
<http://www.vcode.org/>

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.

Josh


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About