Sign in to PrePAN

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



        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


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


how does it compare to 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 for pure-Perl async/await keywords.

Please sign up to post a review.