Skip to content

Commit

Permalink
Use signal.NotifyContext
Browse files Browse the repository at this point in the history
  • Loading branch information
picatz committed Jan 2, 2024
1 parent e38f7ac commit ff5514a
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions cmd/taint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,28 +726,9 @@ func startShell(ctx context.Context) error {
}
}

func interruptContext(ctx context.Context) context.Context {
ctx, cancel := context.WithCancel(ctx)

go func() {
defer cancel()

sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt)

select {
case <-sig:
return
case <-ctx.Done():
return
}
}()

return ctx
}

func main() {
ctx := interruptContext(context.Background())
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()

if err := startShell(ctx); err != nil {
if err == io.EOF {
Expand Down

0 comments on commit ff5514a

Please sign in to comment.