Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Very first pass at signal handlers.
Probably some we could support are missing (though it's an LHF for somebody to add those), and the API is certainly up for discussion. But now there is, at least, a way. Closing the tap doesn't in any way remove the handler yet; that'll come later once the more general cancellation mechanism arrives.
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| my enum Signal ( :SIGINT(1), :SIGBREAK(2), :SIGHUP(3), :SIGWINCH(4) ); | ||
|
|
||
| sub signal(*@signals, :$scheduler = $*SCHEDULER) { | ||
| my class SignalCancellation is repr('AsyncTask') { } | ||
| state %sigmap = | ||
| SIGINT, nqp::const::SIG_INT, | ||
| SIGBREAK, nqp::const::SIG_BREAK, | ||
| SIGHUP, nqp::const::SIG_HUP, | ||
| SIGWINCH, nqp::const::SIG_WINCH; | ||
| my @supplies = @signals.map(-> $sig { | ||
| die "Invalid signal" unless $sig ~~ Signal; | ||
| my $s = Supply.new; | ||
| nqp::signal($scheduler.queue, | ||
| -> $signum { $s.more($signum) }, | ||
| nqp::unbox_i(%sigmap{$sig}), | ||
| SignalCancellation); | ||
| $s | ||
| }); | ||
| @supplies == 1 ?? @supplies[0] !! Supply.merge(@supplies) | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters