Is it possible to call a user defined method within a signal block?
method my-method ( ... ) {
signal(SIGTERM,SIGINT,SIGQUIT,SIGHUP).tap( -> $sig {
say "Received signal: $sig";
self!restore-term();
exit;
} );
...
...
}
On your phone, go to Signal Settings > Privacy > Blocked. Steps to block a number or group: Open Signal on your phone. Open a chat with this contact or phone number. Tap on the chat header with the group name or contact name/number. Choose Block, Block this user, Block this group. Confirm by choosing Block. Choose Ok.
Signals may be blocked to allow critical sections of code to run without interruption. The following functions control signal blocking: block either SAS/C managed signals or USS signals. sigprocmask and sigsuspend are portable to POSIX-conforming systems.
You call a method using a pointer to a function block (for example, pFB^.SampleMethod). In this situation, the pointer can point to instances of the type of the function block and to instances of all derived function blocks.
Attach a function-call initiator to the function-call input port. If you attach an Inport block, open the block, select the Signal Attributes tab, then select the Output function call check box. Configure a Function-Call Subsystem block by setting the Sample time type of its Trigger Port block to triggered or periodic.
Yes, but there are caveats.
signal
provides a Supply
of events, which you can tap
(if you like to) but probably should be using inside a react whenever
structure.
In your example, the tap
takes a Block
(lambda). Every time you call the method, it will set up another Supply
(which is probably not what you want).
This block gets called whenever an event arrives. This means it is completely asynchronous and has no context, other than the lexical context in which the block was created.
So whenever a signal arrives in the Supply
, it will run the block with the self
at the moment the method got called. Which may not be what you expect?
So it feels to me you're asking the wrong question. Apparently you have an object (hopefully a sentinel) that you wish the restore-term
method to be called on whenever someone indicates they want to leave the program. So you're probably better of restructuring your program to something like:
my $sentinel = class.new(...);
react {
whenever signal(SIGTERM,SIGINT,SIGQUIT,SIGHUP) -> $sig {
say "Received signal: $sig";
$sentinel.restore-term();
exit;
}
# .... other stuff
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With