Skip to content

Commit 33915ef

Browse files
committed
Rename, copy, test
1 parent 3aa2a66 commit 33915ef

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

nexus/server.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,33 @@ func WithHandlerContext(ctx context.Context) context.Context {
3434
return context.WithValue(ctx, handlerCtxKey, &handlerCtx{})
3535
}
3636

37-
// InHandlerContext returns true if the given context is a handler context where [AddHandlerLinks] and [HandlerLinks]
37+
// IsHandlerContext returns true if the given context is a handler context where [AddHandlerLinks] and [HandlerLinks]
3838
// can be called. It will only return true when called from an [Operation] handler Start method or from a [Handler]
3939
// StartOperation method.
4040
//
4141
// NOTE: Experimental
42-
func InHandlerContext(ctx context.Context) bool {
42+
func IsHandlerContext(ctx context.Context) bool {
4343
return ctx.Value(handlerCtxKey) != nil
4444
}
4545

4646
// HandlerLinks retrieves the attached links on the given handler context. The returned slice should not be mutated.
47-
// The context provided must be the context passed to the handler or this method will panic, [InHandlerContext] can be
47+
// The context provided must be the context passed to the handler or this method will panic, [IsHandlerContext] can be
4848
// used to verify the context is valid.
4949
//
5050
// NOTE: Experimental
5151
func HandlerLinks(ctx context.Context) []Link {
5252
hctx := ctx.Value(handlerCtxKey).(*handlerCtx)
5353
hctx.mu.Lock()
54-
defer hctx.mu.Unlock()
55-
return hctx.links
54+
links := hctx.links
55+
hctx.mu.Unlock()
56+
cpy := make([]Link, len(links))
57+
copy(cpy, links)
58+
return cpy
5659
}
5760

5861
// AddHandlerLinks associates links with the current operation to be propagated back to the caller. This method
5962
// Can be called from an [Operation] handler Start method or from a [Handler] StartOperation method. The context
60-
// provided must be the context passed to the handler or this method will panic, [InHandlerContext] can be used to
63+
// provided must be the context passed to the handler or this method will panic, [IsHandlerContext] can be used to
6164
// verify the context is valid. This method may be called multiple times for a given handler, each call appending
6265
// additional links. Links will only be attached on successful responses.
6366
//
@@ -71,7 +74,7 @@ func AddHandlerLinks(ctx context.Context, links ...Link) {
7174

7275
// SetHandlerLinks associates links with the current operation to be propagated back to the caller. This method
7376
// Can be called from an [Operation] handler Start method or from a [Handler] StartOperation method. The context
74-
// provided must be the context passed to the handler or this method will panic, [InHandlerContext] can be used to
77+
// provided must be the context passed to the handler or this method will panic, [IsHandlerContext] can be used to
7578
// verify the context is valid. This method replaces any previously associated links, it is recommended to use
7679
// [AddHandlerLinks] to avoid accidental override. Links will only be attached on successful responses.
7780
//

0 commit comments

Comments
 (0)