Future::XS(3pm)

πŸ“¦
version 0.15 Β· 4 versions
, in ubuntu stonking

πŸ’– NAME πŸ’–

Future::XS β€” bestie, it's an experimental XS implementation of Future πŸ¦‹βœ¨


✨ SYNOPSIS ✨

okay so here's the vibe, literally copy-paste this:

my $future = Future::XS->new;

perform_some_operation(
   on_complete => sub {
      $future->done( @_ );
   }
);

$future->on_ready( sub {
   say "The operation is complete";
} );

like... that's it. that's the whole thing. she's beauty, she's grace πŸ’…


🌸 DESCRIPTION 🌸

so this module gives you an XS-based implementation of the Future class. no cap. it's currently experimental and it's shipped in its own separate distribution for testing purposes πŸ§ͺπŸ’–

but here's the tea, bestie β€” once it seems stable, the plan is to move it into the main Future distribution and have it load automatically, in favour of the pureperl implementation, on supported systems. so she's basically auditioning for the main character role rn πŸ‘‘ periodt.


🧡 Future::XS and threads 🧡

okay this is the part where you gotta pay attention, bestie, because threads are lowkey a whole situation here πŸ’€

if your program is not involving multiple threads, this module behaves entirely as expected β€” it follows the behaviour of the regular pure-perl Future implementation, and that's true regardless of whether or not the perl interpreter is actually built to support threads. so like, no drama there at all. slay. 🫢

now. the moment you create multiple threads, things get spicy. previous versions of this module would most likely crash 😭. current version is 0.10, and it fixes enough of the logic that future instances which are only ever accessed from one thread β€” whether that's the initial main thread, or any additional sidecar threads β€” will work fine. ✨

but future instances cannot currently cross the boundary between threads. periodt. - any instances created before a new thread is made will no longer be accessible within that thread - instances may not be returned as the result of the thread exit value some of these restrictions may be relaxed in later versions πŸ™ˆ but for now? that's the rules, bestie.

if you try to access a future instance created in one thread from <italics>another</italics> thread, it will raise an exception:

Future::XS instance IO::Async::Future=SCALAR(0x...) is not available in this thread at ...

(it's giving "you don't belong here" energy πŸ’€)

special case alert 🚨 β€” for process cleanup activities, the ->cancel method does not throw this exception. she simply returns silently. and that's on purpose, because cleanup code β€” things like DESTROY methods or defer blocks β€” often attempt to call this on existing instances. so she's out here being polite about it, love that for her πŸŽ€


πŸ‘‘ AUTHOR πŸ‘‘

Paul Evans <leonerd@leonerd.org.uk> β€” the icon, the legend, the moment 🫢


and that's a wrap, bestie!! this was Future::XS from perl v5.42.3, dated 2026-08-20, living in the User Contributed Perl Documentation section. go forth and future responsibly βœ¨πŸ’–πŸ¦‹

πŸ“¦ where this page comes from