Promise::AsyncAwait - Async/await with promises
use Promise::AsyncAwait; async sub get_number_plus_1 { my $number = await _get_number_p(); return 1 + $number; } my $p = get_number_plus_1()->then( sub { say "number: " . shift } );
… and then use whatever mechanism you will for “unrolling” $p.
$p
Future::AsyncAwait implements JavaScript-like async/await semantics for Perl, but it defaults to using CPAN’s Future rather than promises. The two are similar but incompatible.
Use this module for a promise-oriented async/await instead. It’s actually just a shim around Future::AsyncAwait that feeds it configuration options for Promise::XS promises rather than Future. This yields a friendlier (and likely faster!) experience for those more accustomed to JavaScript promises than to CPAN Future.
This should work with most CPAN promise implementations.
Copyright 2021 Gasper Software Consulting. All rights reserved.
This library is licensed under the same license as Perl.
To install Promise::AsyncAwait, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Promise::AsyncAwait
CPAN shell
perl -MCPAN -e shell install Promise::AsyncAwait
For more information on module installation, please visit the detailed CPAN module installation guide.