NAME
UniEvent::Signal - runs callbacks upon UNIX signals
SYNOPSIS
use UniEvent::Signal; # for constants
my $h = UE::signal SIGINT, sub { say "got SIGINT" };
# more verbose way
my $h = UniEvent::Signal->new();
$h->start(SIGINT, sub {
my ($h, $signum) = @_;
say "got signal $signum";
});
# one shot signal watcher
$h->once(SIGTERM, sub { ... });
DESCRIPTION
Allow to check UNIX signals and, if a signal appears, execute appropriate handlers during loop iteration.
It is inherited from UniEvent::Handle.
METHODS
All methods of UniEvent::Handle also apply.
create($signum, $callback, [$loop = default])
my $handle = UniEvent::Signal->create(SIGINT, sub { say "hi" });
Creates and starts a signal handle. Alias for new($loop)
+ start($signum, $callback)
.
create_once($signum, $callback, [$loop = default])
my $handle = UniEvent::Signal->create_once(SIGINT, sub { say "hi" });
Creates and starts a one-shot signal handle. Alias for new($loop)
+ once($signum, $callback)
.
new([$loop = default])
Constructs new Signal handle and binds it to the specified event loop.
start($signum, [$callback])
Marks $signum
to be permanently handled in the next event loop iterations.
If $callback
is present, it is added as event()->add($cb)
once($signum, [$callback])
Temporally marks $signum
to be watched in the next event loop iteration(s). Upon $signum
receiving, handle will no longer watch for it (as if stop()
was called).
If $callback
is present, it is added as event()->add($cb)
stop()
Stops the singal handle, i.e. makes it inactive for the next event loop iteration.
callback($sub)
event()
Callback signature:
my ($handle, $signum) = @_;
Where $handle
is the Signal handle object itself.
$signum
is the signal number that fired. It is useful when you add the same callback for several signal watchers.
See "EVENT CALLBACKS" in UniEvent
event_listener($delegate, [$weak])
Method on_signal
will be called.
See "EVENT LISTENER" in UniEvent
call_now($signum)
Immediately ivokes assigned callbacks and listeners in the caller context (i.e. not waiting loop run) with the given signal.
CONSTANTS
Some signals might be not available for particular platforms.