callbacks

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalHandlers []Handler

Functions

func AppendHandlers added in v0.3.4

func AppendHandlers(ctx context.Context, info *RunInfo, handlers ...Handler) context.Context

func InitCallbacks

func InitCallbacks(ctx context.Context, info *RunInfo, handlers ...Handler) context.Context

func On

func On[T any](ctx context.Context, inOut T, handle Handle[T], timing CallbackTiming) (context.Context, T)

func OnEndHandle

func OnEndHandle[T any](ctx context.Context, output T,
	runInfo *RunInfo, handlers []Handler) (context.Context, T)

func OnEndWithStreamOutputHandle

func OnEndWithStreamOutputHandle[T any](ctx context.Context, output *schema.StreamReader[T],
	runInfo *RunInfo, handlers []Handler) (context.Context, *schema.StreamReader[T])

func OnErrorHandle

func OnErrorHandle(ctx context.Context, err error,
	runInfo *RunInfo, handlers []Handler) (context.Context, error)

func OnStartHandle

func OnStartHandle[T any](ctx context.Context, input T,
	runInfo *RunInfo, handlers []Handler) (context.Context, T)

func OnStartWithStreamInputHandle

func OnStartWithStreamInputHandle[T any](ctx context.Context, input *schema.StreamReader[T],
	runInfo *RunInfo, handlers []Handler) (context.Context, *schema.StreamReader[T])

func OnWithStreamHandle added in v0.3.4

func OnWithStreamHandle[S any](
	ctx context.Context,
	inOut S,
	handlers []Handler,
	cpy func(int) []S,
	handle func(context.Context, Handler, S) context.Context) (context.Context, S)

func ReuseHandlers added in v0.3.4

func ReuseHandlers(ctx context.Context, info *RunInfo) context.Context

Types

type CallbackInput

type CallbackInput any

type CallbackOutput

type CallbackOutput any

type CallbackTiming

type CallbackTiming uint8

type CtxManagerKey

type CtxManagerKey struct{}

type Handle

type Handle[T any] func(context.Context, T, *RunInfo, []Handler) (context.Context, T)

type Handler

type Handler interface {
	OnStart(ctx context.Context, info *RunInfo, input CallbackInput) context.Context
	OnEnd(ctx context.Context, info *RunInfo, output CallbackOutput) context.Context

	OnError(ctx context.Context, info *RunInfo, err error) context.Context

	OnStartWithStreamInput(ctx context.Context, info *RunInfo,
		input *schema.StreamReader[CallbackInput]) context.Context
	OnEndWithStreamOutput(ctx context.Context, info *RunInfo,
		output *schema.StreamReader[CallbackOutput]) context.Context
}

type RunInfo

type RunInfo struct {
	Name      string
	Type      string
	Component components.Component
}

type TimingChecker

type TimingChecker interface {
	Needed(ctx context.Context, info *RunInfo, timing CallbackTiming) bool
}

Jump to

Keyboard shortcuts

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