operation

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindOperation

func FindOperation[T any, O interface {
	Operation
	*T
}](ctx context.Context) (*T, bool)

FindOperation returns the Operation of T if the context has the Operation of T. This is used to identify the relationship between application processes.

func FinishOperation

func FinishOperation[O Operation, E ResultOf[O]](op O, results E)

FinishOperation finishes the operation. This function notifies the event listeners of the operation and the parent operation.

func InitRootOperation

func InitRootOperation(op Operation)

InitRootOperation initializes the root operation. The root operation should be passed to op created by NewRootOperation.

func IsRootOperationInitialized

func IsRootOperationInitialized() bool

func OnFinish

func OnFinish[O Operation, E ResultOf[O]](op Operation, l EventListener[O, E])

OnFinish registers the event listener to the operation.

func OnStart

func OnStart[O Operation, E ArgOf[O]](op Operation, l EventListener[O, E])

On registers the event listener to the operation.

func RegisterOperation

func RegisterOperation(ctx context.Context, op Operation) context.Context

RegisterOperation registers the operation to the context.

func StartAndRegisterOperation

func StartAndRegisterOperation[O Operation, E ArgOf[O]](ctx context.Context, op O, args E) context.Context

StartAndRegisterOperation starts the operation and registers the operation to the context.

func StartOperation

func StartOperation[O Operation, E ArgOf[O]](op O, args E)

StartOperation starts the operation. This function notifies the event listeners of the parent operation.

Types

type ArgOf

type ArgOf[O Operation] interface {
	IsArgOf(O)
}

IsArgOf is a marker interface that marks the type as an argument of the operation.

type EventListener

type EventListener[O Operation, T any] func(O, T)

EventListener is a function type that is called when an event is emitted. At the start and end of the Operation, you can execute func(O, T)

type Operation

type Operation interface {
	// GetRootID returns the root operation ID.
	GetRootID() string
	// GetID returns the operation ID.
	GetID() string
	// Parent returns the parent operation.
	Parent() Operation
	// contains filtered or unexported methods
}

Operation is the interface that wraps the basic operation methods. An operation is a unit of application process (e.g. HTTP Request handling, Execute SQL Query, etc...) that can be started and finished. When an operation is started or finished, events are notified to event listeners.

func FindOperationFromContext

func FindOperationFromContext(ctx context.Context) (Operation, bool)

FindOperationFromContext returns the operation from the context. This is used to share operations between application processes such as executing SQL queries and sending HTTP requests.

func NewOperation

func NewOperation(parent Operation) Operation

NewOperation creates a new operation.

func NewRootOperation

func NewRootOperation() Operation

NewRootOperation creates a new root operation.

type ResultOf

type ResultOf[O Operation] interface {
	IsResultOf(O)
}

IsResultOf is a marker interface that marks the type as a result of the operation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL