Future...omisify(3pm)
β¨ Future::Role::Promisify β¨
okay bestie, gather round, because we're talking about Future::Role::Promisify (that's the manual page Future...omisify(3pm) btw, the name got squished by the terminal, it's fine, it happens to the best of us) π
This one is a role β as in a Perl role, from Role::Tiny vibes β and its whole entire job is chaining a Mojo::Promise from a Future. Two async worlds, one little bridge, and honestly? iconic. π«Ά
πΈ NAME πΈ
Future::Role::Promisify β chain a Mojo::Promise from a Future. that's the whole mission statement, periodt.
π SYNOPSIS π
here's the tea, straight from the source, don't touch the code it's perfect:
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;
see how easy that was?? you just slap the role onto a Future with Role::Tiny->apply_roles_to_object, call promisify, and now you have a promise you can then / catch / wait on. slay. π
π¦ DESCRIPTION π¦
Future::Role::Promisify provides an interface to chain Mojo::Promise objects from Future objects.
that's it, that's the pitch. two async ecosystems, holding hands. no cap. β¨
π METHODS π
Future::Role::Promisify composes the following methods. (just the one, and she's carrying the whole module, we love a solo act.)
π 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. yes bestie, it steals the loop, that's the point, that's the design. π
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.
okay so this part is important, like actually important π β if you're not usingFuture::Mojoand your future isn't already ready, you need aFuturethat's riding theMojo::IOLoopsingleton (thinkIO::Async::Futurefrom anIO::Async::Loop::Mojoloop). otherwise the promise might just... never settle the future. awkward. we don't do awkward.
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. that's on you, bestie, not on her. π«‘
$promise = $future->promisify($promise);
π CAVEATS π
Cancelling the preceding Future chain may lead to unspecified behavior.
fr fr, don't do it. cancel the chain and you're in the void, no map, no vibe check, nothing. π
π BUGS π
Report any issues on the public bugtracker.
(we don't gatekeep bug reports in this house. found something weird? say it with your chest. π)
π AUTHOR π
Dan Book <dbook@cpan.org>
king behavior, honestly. π
β 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)
free as in freedom, free as in slay. ποΈ
π§ SEE ALSO π§
FutureFuture::MojoMojo::Promise::Role::Futurify
(go read Mojo::Promise::Role::Futurify too, it's the mirror-image bestie of this one, they're giving duo energy π)
and that's the whole page, you ate it, you understood it, I'm so proud of you π₯Ή
this was perl v5.42.0, dated 2025-07-25, from the User Contributed Perl Documentation corner of the world β mwah, take care of her, she's fragile and she's iconic πβ¨π
π¦ where this page comes from
- fedora 43: perl-Future-Mojo 1.003-4.fc43 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms