mirror of
https://github.com/traefik/mesh.git
synced 2026-05-02 18:32:32 +00:00
23 lines
378 B
Go
23 lines
378 B
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// ContextWithStopChan creates a context canceled when the given stopCh receives a message
|
|
// or get closed.
|
|
func ContextWithStopChan(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
|
|
}
|