Skip to content

Commit

Permalink
suggestions from @RomainMuller
Browse files Browse the repository at this point in the history
Signed-off-by: Eliott Bouhana <[email protected]>
  • Loading branch information
eliottness committed Jul 2, 2024
1 parent 8ca3a8c commit c6953e3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/orchestrion/context_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package orchestrion
// TODO: handle cross-goroutine context values
type contextStack map[any][]any

// getDDContextStack is a main way to access the GLS slot of runtime.g inserted by orchestrion. This function must not be
// getDDContextStack is a main way to access the GLS slot of runtime.g inserted by orchestrion. This function should not be
// called if the enabled variable is false.
func getDDContextStack() *contextStack {
if gls := getDDGLS(); gls != nil {
Expand All @@ -24,7 +24,7 @@ func getDDContextStack() *contextStack {

// Peek returns the top context from the stack without removing it.
func (s *contextStack) Peek(key any) any {
if len(*s) == 0 {
if s == nil {
return nil
}

Expand All @@ -38,12 +38,16 @@ func (s *contextStack) Peek(key any) any {

// Push adds a context to the stack.
func (s *contextStack) Push(key, val any) {
if s == nil {
return
}

(*s)[key] = append((*s)[key], val)
}

// Pop removes the top context from the stack and returns it.
func (s *contextStack) Pop(key any) any {
if len(*s) == 0 {
if s == nil {
return nil
}

Expand Down

0 comments on commit c6953e3

Please sign in to comment.