IO::As...:Signal(3pm)

πŸ’– NAME πŸ’–

IO::Async::Signal β€” event callback on receipt of a POSIX signal


✨ SYNOPSIS ✨

use IO::Async::Signal;

use IO::Async::Loop;
my $loop = IO::Async::Loop->new;

my $signal = IO::Async::Signal->new(
   name => "HUP",

   on_receipt => sub {
       print "I caught SIGHUP\n";
   },
);

$loop->add( $signal );

$loop->run;

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so bestie, picture this: IO::Async::Signal is a subclass of IO::Async::Notifier, and what it does is literally fire off its callback the moment a particular POSIX signal shows up. the way it just... catches the vibe check from the kernel πŸ’… iconic behaviour fr fr.

and here's the cute part β€” you can have multiple objects added to a Loop that are all watching for the same signal. every single one of those callbacks is gonna get invoked, and they go in no particular order. so like, don't go assuming who runs first, bestie, because nobody knows 🌸. friendship bracelet energy: everyone gets their turn, order is whatever.


πŸ”₯ EVENTS πŸ”₯

so these events get invoked either by using subclass methods or CODE references in parameters β€” your choice, we don't gatekeep 🫢.

🌈 on_receipt

Invoked when the signal is received. that's it, that's the whole thing. the signal arrives, this goes off πŸ’₯.


πŸŽ€ PARAMETERS πŸŽ€

these named parameters can be passed to new or configure β€” pick your entry point, both slay:

⭐ name => STRING

the name of the signal you wanna watch. it should be a bare name like "TERM" β€” no SIG prefix, no fancy business, just the raw name okay.

⚠️ heads up: this one can only be given at construction time. after that? closed for business, no takebacks, periodt.

πŸ’œ on_receipt => CODE

a CODE reference for the on_receipt event. that's your lil function that runs on receipt, yk?

🫢 and listen β€” once you've constructed the Signal, you still need to add it to the Loop before it'll work. don't just make it and ghost it, it needs the loop to actually do its thing bestie.

πŸ‘‘ AUTHOR πŸ‘‘

Paul Evans <leonerd@leonerd.org.uk>


and that's a wrap!! this page came to you courtesy of perl v5.40.1, stamped 2026-02-21, from the User Contributed Perl Documentation collection no cap πŸ’–βœ¨ go catch some signals, you got this πŸ’…

πŸ“¦ where this page comes from