Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions runtime/context/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023-present Datadog, Inc.

package context

// Stack is a generic stack type that can be used to store values of any type.
type Stack[T any] []T

// Hooks is an interface that allows users to hook into the execution of a program when context propagation would matter
// to define a custom behavior for context propagation.
type Hooks[T any] interface {
// Main is called before the main function of the program is executed.
Main() *Stack[T]

// Go is called when a new goroutine is created. // It receives the parent stack and returns a new stack for the goroutine.
Go(parent *Stack[T]) *Stack[T]

// ChanRecv is called when a value is received from a channel.
// It receives the parent stack and the stack of the sender goroutine, and returns a new stack for the receiving goroutine.
ChanRecv(parent *Stack[T], sent *Stack[T]) *Stack[T]

// ChanSend is called when a value is sent to a channel. The returned value will be passed as the `sent` argument to ChanRecv.
ChanSend(parent *Stack[T]) *Stack[T]
}

// Controller is an interface to push and pull values from the current context stack.
type Controller[T any] struct {
// ...
}

func (c *Controller[T]) Push(_ T) {

Check failure on line 33 in runtime/context/api.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (macos-latest | main)

unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)

Check failure on line 33 in runtime/context/api.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (ubuntu-latest | main)

unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)

Check failure on line 33 in runtime/context/api.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (windows-latest | main)

unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)
}

func (c *Controller[T]) Pop() T {

Check failure on line 36 in runtime/context/api.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (macos-latest | main)

unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)

Check failure on line 36 in runtime/context/api.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (ubuntu-latest | main)

unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)

Check failure on line 36 in runtime/context/api.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (windows-latest | main)

unused-receiver: method receiver 'c' is not referenced in method's body, consider removing or renaming it as _ (revive)
var x T
return x
}

// Register registers the hooks for the given type T and returns a Controller[T] that can be used to push and pull values from the current stack.
// The context key used to track this propagation is the type T itself
func Register[T any](_ Hooks[T]) *Controller[T] {
return nil
}
Loading