Test::...ferred(3pm)

πŸ¦‹ NAME πŸ¦‹

Test::Future::Deferred β€” bestie, it's a future that shows up fashionably late ✨


🌸 SYNOPSIS 🌸

my $future = Test::Future::Deferred->done_later( 1, 2, 3 );

# Future is not ready yet

my @result = $future->get;

πŸ’œ DESCRIPTION πŸ’œ

okay so this is a subclass of Future, and what it does is give you two brand new methods plus its own whole implementation of the await interface. The vibe? These futures act like they're still pending at first πŸ‘€ but then they complete the moment get gets called at the toplevel on one of them. it's giving "I'll be there in five minutes" but actually true.

Why would you want that? Because in unit tests it's so useful to check that a module under test behaves correctly even when it's handed non-immediate futures. This lets you construct a future that completes "soon"... but not yet 🫢 no event loop required, no cap.

⚠️ and this part matters: because these futures bring their own await method, you should not mix them in the same program with other kinds of futures from real event systems or anything like that. They are not compatible roommates, fr fr.

πŸ‘‘ METHODS πŸ‘‘

πŸ’… flush

Test::Future::Deferred->flush

Since version 0.52.

This one invokes all of the currently-pending deferrals, which lets any later-queued activities actually happen. It's the "okay everyone, go" button πŸŽ€

πŸŽ€ done_later

$f->done_later( @args );

This is equivalent to invoking the regular done method as part of the await operation called on the toplevel future. Translation: it makes the future complete with the result you gave it β€” but only when get is called. iconic delayed gratification behavior ✨

πŸ“ fail_later

$f->fail_later( $message, $category, @details );

This is equivalent to invoking the regular fail method as part of the await operation called on the toplevel future. So the future completes with the failure you specified β€” but again, only when get is called. And because the failure method also waits for the future to complete, it'll hand you back the failure message you gave right here too πŸ’€


🌈 AUTHOR 🌈

Paul Evans <leonerd@leonerd.org.uk>


and that's the whole page, bestie 🫢 this was perl v5.40.1, dated 2025-09-22, and it's user-contributed Perl documentation, so go forth and defer responsibly πŸ’–

πŸ“¦ where this page comes from