Skip to content

Commit df7dbc1

Browse files
authored
Merge pull request #205 from cschleiden/with-value
Expose `WithValue`
2 parents e1d937e + a253949 commit df7dbc1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

workflow/context.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ func WithCancel(parent Context) (ctx Context, cancel CancelFunc) {
1414
return sync.WithCancel(parent)
1515
}
1616

17+
// WithValue returns a copy of parent in which the value associated with key is
18+
// val.
19+
//
20+
// Use context Values only for request-scoped data that transits processes and
21+
// APIs, not for passing optional parameters to functions.
22+
//
23+
// The provided key must be comparable and should not be of type
24+
// string or any other built-in type to avoid collisions between
25+
// packages using context. Users of WithValue should define their own
26+
// types for keys. To avoid allocating when assigning to an
27+
// interface{}, context keys often have concrete type
28+
// struct{}. Alternatively, exported context key variables' static
29+
// type should be a pointer or interface.
30+
func WithValue(parent Context, key, val interface{}) Context {
31+
return sync.WithValue(parent, key, val)
32+
}
33+
1734
func NewDisconnectedContext(ctx Context) Context {
1835
return sync.NewDisconnectedContext(ctx)
1936
}

0 commit comments

Comments
 (0)