diff --git a/Justfile b/Justfile index 63dfa2d..a2bddb5 100644 --- a/Justfile +++ b/Justfile @@ -13,6 +13,12 @@ default: tidy: go mod tidy +# run specific unit test +[group('build')] +[no-cd] +test unit: + go test -v -count=1 -race -run {{unit}} 2>/dev/null + # run tests across source tree [group('build')] tests: diff --git a/context.go b/context.go index 8aeeb2a..fb63dea 100644 --- a/context.go +++ b/context.go @@ -42,3 +42,13 @@ func WithCancel(c C) (C, Cancel) { func WithTTL(c C, duration time.Duration) (C, Cancel) { return context.WithTimeout(c, duration) } + +// WithValue wraps an existing Context with value set for key. +func WithValue[K, V any](c C, key K, value V) C { + return context.WithValue(c, key, value) +} + +// Value retrieves the value associated with the given key. +func Value[K, V any](c C, key K) V { + return c.Value(key).(V) +}