Skip to content

Commit 69e732b

Browse files
authored
c: support for values (#18)
1 parent d8366f3 commit 69e732b

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Justfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ default:
1313
tidy:
1414
go mod tidy
1515

16+
# run specific unit test
17+
[group('build')]
18+
[no-cd]
19+
test unit:
20+
go test -v -count=1 -race -run {{unit}} 2>/dev/null
21+
1622
# run tests across source tree
1723
[group('build')]
1824
tests:

context.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@ func WithCancel(c C) (C, Cancel) {
4242
func WithTTL(c C, duration time.Duration) (C, Cancel) {
4343
return context.WithTimeout(c, duration)
4444
}
45+
46+
// WithValue wraps an existing Context with value set for key.
47+
func WithValue[K, V any](c C, key K, value V) C {
48+
return context.WithValue(c, key, value)
49+
}
50+
51+
// Value retrieves the value associated with the given key.
52+
func Value[K, V any](c C, key K) V {
53+
return c.Value(key).(V)
54+
}

0 commit comments

Comments
 (0)