Skip to content

Commit

Permalink
Fix bug in SignalHandler (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbourgon authored Jan 27, 2024
1 parent 145e764 commit eee6e04
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func SignalHandler(ctx context.Context, signals ...os.Signal) (execute func() er
type testSigChanKey struct{}

func getTestSigChan(ctx context.Context) <-chan os.Signal {
return ctx.Value(testSigChanKey{}).(<-chan os.Signal) // can be nil
c, _ := ctx.Value(testSigChanKey{}).(<-chan os.Signal) // can be nil
return c
}

func putTestSigChan(ctx context.Context, c <-chan os.Signal) context.Context {
Expand Down
8 changes: 8 additions & 0 deletions actors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ func TestSignalError(t *testing.T) {
t.Errorf("errors.Is(err, ErrSignal): want %v, have %v", want, have)
}
}

func TestSignalHandlerNil(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
var rg Group
rg.Add(SignalHandler(ctx, os.Interrupt))
cancel()
t.Logf("%v", rg.Run())
}

0 comments on commit eee6e04

Please sign in to comment.