Future::Role::Promisify - Chain a Mojo::Promise from a Future
use IO::Async::Loop::Mojo; use Role::Tiny (); my $loop = IO::Async::Loop::Mojo->new; my $future = $loop->timeout_future(after => 5); Role::Tiny->apply_roles_to_object($future, 'Future::Role::Promisify'); $future->promisify->then(sub { say 'Resolved' })->catch(sub { warn 'Rejected' })->wait; use Future::Mojo; use Mojo::IOLoop; my $loop = Mojo::IOLoop->new; my $future = Future::Mojo->new($loop); $loop->timer(1 => sub { $future->done('Success!') }); $future->promisify->then(sub { say @_ })->wait;
Future::Role::Promisify provides an interface to chain Mojo::Promise objects from Future objects.
Future::Role::Promisify composes the following methods.
my $promise = $future->promisify;
Returns a Mojo::Promise object that will resolve or reject when the Future becomes ready. It will be assigned the Mojo::IOLoop of the Future if it is an instance of Future::Mojo.
If the Future is not immediately ready or an instance of Future::Mojo, it must be an instance of a Future that uses the Mojo::IOLoop singleton, such as an IO::Async::Future from the IO::Async::Loop::Mojo loop. In any other circumstances, the resulting Mojo::Promise may not be able to settle the Future.
If a promise object is passed, it will be used and returned instead of constructing a new Mojo::Promise. It may be an object of any class that has a standard Promises/A+ API (in particular resolve and reject methods), but you are responsible for ensuring that it uses the correct event loop to settle the Future if needed.
resolve
reject
$promise = $future->promisify($promise);
Cancelling the preceding Future chain may lead to unspecified behavior.
Report any issues on the public bugtracker.
Dan Book <dbook@cpan.org>
This software is Copyright (c) 2019 by Dan Book.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
Future, Future::Mojo, Mojo::Promise::Role::Futurify
To install Future::Mojo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Future::Mojo
CPAN shell
perl -MCPAN -e shell install Future::Mojo
For more information on module installation, please visit the detailed CPAN module installation guide.