Skip to content

Commit

Permalink
Exit with code 1 when gotten second signal
Browse files Browse the repository at this point in the history
  • Loading branch information
chapsuk committed Dec 12, 2018
1 parent ea0e779 commit 5451e57
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

// ShutdownContext returns child context from passed context which will be canceled
// on incoming signals: SIGINT, SIGTERM, SIGHUP
// on incoming signals: SIGINT, SIGTERM, SIGHUP.
// Ends immediately by os.Exit(1) after second signal
func ShutdownContext(c context.Context) context.Context {
ctx, cancel := context.WithCancel(c)
go func() {
Expand All @@ -19,6 +20,8 @@ func ShutdownContext(c context.Context) context.Context {
return
case <-ch:
cancel()
<-ch
os.Exit(1)
}
}()
return ctx
Expand Down

0 comments on commit 5451e57

Please sign in to comment.