wisski-cloud-distillery/pkg/cancel/values.go
2023-01-06 18:59:06 +01:00

24 lines
554 B
Go

package cancel
import "context"
// ValuesOf returns a new context that has the same deadline and cancelation behviour as parent.
// However when requesting values from the context, checks the values in context first.
func ValuesOf(parent, values context.Context) context.Context {
return &valuesOf{
Context: parent,
values: values,
}
}
type valuesOf struct {
context.Context
values context.Context
}
func (vv *valuesOf) Value(key any) any {
if value := vv.values.Value(key); value != nil {
return value
}
return vv.Context.Value(key)
}