PrePAN

Sign in to PrePAN

Promise::Syntax async/await comprehension syntax in pure perl

Good

Synopsis

        use Promise::Syntax;

	my $result_promise = async
		await { v1 => promise1() },
		await { v2 => promise2( $_->{v1} ) },
		await { _ => log_promise( "acquired values: ".join( ', ', @$_{ qw(v1 v2) } ) ) },
		as { $_->{v1} + $_->{v2} }; # Value that will be returned by the $result_promise

Description

This is a 'bicycle' i use for some time in my system tests.

Comments

how does it compare to Future::AsyncAwait?

https://en.wikipedia.org/wiki/Async/await#In_Perl_5
https://metacpan.org/pod/Future::AsyncAwait
This module provides syntax sugar similar to that of Future::AsyncAwait.

However, Future::AsyncAwait hooks deeply into Perl interpreter and requires loading compiled code which is not acceptable for some environments.

Promise::Syntax is implemented pure Perl without source filters and other similar features.
Essentially, it only simplifies ->then( sub { ... } ) chains.

No support for "try { ... } catch { ... }" is planned (which should be present in a good async/await implementation).
If being a pure Perl implementation is the defining feature of this module then it might be a good idea to include a "PP" in the name somewhere.
There's also https://metacpan.org/pod/PerlX::AsyncAwait for pure-Perl async/await keywords.

Please sign up to post a review.