Skip to content

Commit

Permalink
Deregister signal channel (#16)
Browse files Browse the repository at this point in the history
If `SignalHandler` is being used as a mechanism to exit the program
entirely, these resources will be cleaned up naturally. But if not,
the signal should be explicitly deregistered.

Make sure the channel is eligible to be garbage collected and that no
additional signals should be delivered to the channel after this actor
exits.
  • Loading branch information
alindeman authored May 8, 2020
1 parent 0c58000 commit c709688
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func SignalHandler(ctx context.Context, signals ...os.Signal) (execute func() er
return func() error {
c := make(chan os.Signal, 1)
signal.Notify(c, signals...)
defer signal.Stop(c)
select {
case sig := <-c:
return SignalError{Signal: sig}
Expand Down

0 comments on commit c709688

Please sign in to comment.