package util import ( "context" ) func ContextWithStopCh(ctx context.Context, stopCh <-chan struct{}) context.Context { ctx, cancel := context.WithCancel(ctx) go func() { defer cancel() select { case <-ctx.Done(): case <-stopCh: } }() return ctx }