Future...omisify(3pm)

πŸ“¦
version 1.003 Β· 3 versions
, in fedora 43

✨ 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 using Future::Mojo and your future isn't already ready, you need a Future that's riding the Mojo::IOLoop singleton (think IO::Async::Future from an IO::Async::Loop::Mojo loop). 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. πŸ‘‘


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 🧚

  • Future
  • Future::Mojo
  • Mojo::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