Manpage logo

Future::Role::Promisify - Chain a Mojo::Promise from a Future

NAME  SYNOPSIS  DESCRIPTION  METHODS  promisify  CAVEATS  BUGS  AUTHOR  COPYRIGHT AND LICENSE  SEE ALSO 

NAME

Future::Role::Promisify − Chain a Mojo::Promise from a Future

SYNOPSIS

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;

DESCRIPTION

Future::Role::Promisify provides an interface to chain Mojo::Promise objects from Future objects.

METHODS

Future::Role::Promisify composes the following methods.

promisify

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.

$promise = $future−>promisify($promise);

CAVEATS

Cancelling the preceding Future chain may lead to unspecified behavior.

BUGS

Report any issues on the public bugtracker.

AUTHOR

Dan Book <[email protected]>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2019 by Dan Book.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

SEE ALSO

Future, Future::Mojo, Mojo::Promise::Role::Futurify


Updated 2026-06-01 - jenkler.se | uex.se