Async-Methods
view release on metacpan or search on metacpan
NAME
Async::Methods - Namespaced sugar methods for async/await and
future/promise based code
SYNOPSIS
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
# Normal synchronous code
print $ua->get('http://trout.me.uk/')->result->body;
# Equivalent code running synchronously atop promises
print $ua->get_p('http://trout.me.uk')->then::result->await::body;
# Equivalent code within an async subroutine
use Mojo::Base -async_await, -signatures;
async sub fetch ($url) {
await $ua->get_p($url)->then::result->then::body;
}
print fetch($url)->await::this;
DESCRIPTION
Async::Methods provides a set of helper methods operating via namespace
that make chaining together asynchronous methods easier. This is not at
all meant to be a replacement for the "async" and "await" keywords
available via Future::AsyncAwait or the "-async_await" flag to
Mojo::Base and in fact is largely meant to be used *with* such
facilities.
Note that in the following code I use $p for example variables but they
can be Future or Mojo::Promise objects or (hopefully) objects of any
other class that provides a similar interface.
Note that methods of each type provided can be called three ways:
lib/Async/Methods.pm view on Meta::CPAN
=head1 NAME
Async::Methods - Namespaced sugar methods for async/await and future/promise based code
=head1 SYNOPSIS
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
# Normal synchronous code
print $ua->get('http://trout.me.uk/')->result->body;
# Equivalent code running synchronously atop promises
print $ua->get_p('http://trout.me.uk')->then::result->await::body;
# Equivalent code within an async subroutine
use Mojo::Base -async_await, -signatures;
async sub fetch ($url) {
await $ua->get_p($url)->then::result->then::body;
}
print fetch($url)->await::this;
=head1 DESCRIPTION
L<Async::Methods> provides a set of helper methods operating via namespace
that make chaining together asynchronous methods easier. This is not at all
meant to be a replacement for the C<async> and C<await> keywords available
via L<Future::AsyncAwait> or the C<-async_await> flag to L<Mojo::Base> and
in fact is largely meant to be used I<with> such facilities.
Note that in the following code I use C<$p> for example variables but they
can be L<Future> or L<Mojo::Promise> objects or (hopefully) objects of any
other class that provides a similar interface.
Note that methods of each type provided can be called three ways:
( run in 0.256 second using v1.01-cache-2.11-cpan-0d8aa00de5b )