From 7a8c04890829e9fd765e8a964f0223bec6ffcb53 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Sun, 26 Apr 2026 06:31:58 -0500 Subject: [PATCH] c: support for values --- Justfile | 6 ++++++ context.go | 10 ++++++++++ 2 files changed, 16 insertions(+) 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) +}