Skip to content

Instantly share code, notes, and snippets.

View bronger's full-sized avatar

Torsten Bronger bronger

  • Research Centre Jülich
  • Aachen
View GitHub Profile
@matejb
matejb / sigterm_context.go
Created May 20, 2017 12:21
Golang context with cancellation on signal receive
func contextWithSigterm(ctx context.Context) context.Context {
ctxWithCancel, cancel := context.WithCancel(ctx)
go func() {
defer cancel()
signalCh := make(chan os.Signal, 1)
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
select {
case <-signalCh: