Skip to content

Commit

Permalink
Exit from goroutine if context was cancelled (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanmhlv authored and chapsuk committed Sep 28, 2018
1 parent 91b5357 commit ea0e779
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ func ShutdownContext(c context.Context) context.Context {
go func() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
<-ch
cancel()
select {
case <-ctx.Done():
return
case <-ch:
cancel()
}
}()
return ctx
}

0 comments on commit ea0e779

Please sign in to comment.