events

package
v0.104.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package events provides the generic, typed @events route directive.

Index

Constants

View Source
const ID = "events"

Variables

View Source
var Directive = compiler.Directive{
	Name:        "events",
	Example:     "@events {\n  observe thttp.events.listener_ready -> thttp.listener_ready_sink\n}",
	Handler:     handleDirective,
	OpaqueBlock: true,
}

Directive parses newline-separated routes to direct typed event sinks.

Functions

func Bundle

func Bundle(_ map[string]string) compiler.Bundle

func InstallPublisher

func InstallPublisher(ctx context.Context, meta map[string]any) context.Context

InstallPublisher composes the source's explicit routes with any publisher supplied by the host. The host publisher receives the original payload and context; it may retain the caller-owned payload. No pooled or shared payload state is used by the route table.

func IsRouteInvocation

func IsRouteInvocation(ctx context.Context) bool

IsRouteInvocation reports whether ctx is executing a legacy route invocation.

func MaterializeRoutes

func MaterializeRoutes(req compiler.MaterializeReq) error

MaterializeRoutes resolves explicit event sources and direct typed sinks from the mounted Catalog resolver. Routed sinks must implement the non-retaining contract; arbitrary expressions and dynamically coerced actions are rejected.

func PublishFromBundle

func PublishFromBundle[T any](ctx context.Context, bundleID, subject string, payload *T) error

PublishFromBundle publishes a caller-owned typed event through the publisher injected with Kernel's xctx.EventPublisher seam. Payload must point to an immutable event value that the caller will not mutate or reuse; host delegates may retain it. The local route sink is synchronous and must not retain it.

func WithRouteInvocation

func WithRouteInvocation(ctx context.Context) context.Context

WithRouteInvocation marks an action context as being used for a route sink. Typed event sinks are now invoked directly and do not need this marker.

Types

type NonRetainingEventSink

type NonRetainingEventSink interface {
	EventPayloadType() reflect.Type
	HandleEvent(context.Context, any) error
}

NonRetainingEventSink is the synchronous route contract for typed event sinks. Implementations must not retain or mutate the payload or context after the call returns. PayloadType must be the exact pointer type accepted by HandleEvent. Event sinks are invoked directly, outside action execution and journal steps.

type NonRetainingEventSinkAction

type NonRetainingEventSinkAction interface {
	action.AnyAction
	NonRetainingEventSink
}

NonRetainingEventSinkAction is both a Catalog-mountable action and a typed synchronous event sink.

func NewNonRetainingEventSink

func NewNonRetainingEventSink[T any](name string, handler func(context.Context, *T) error) NonRetainingEventSinkAction

NewNonRetainingEventSink creates a Catalog-resolvable typed sink action. Its route path calls handler directly with the original caller-owned *T payload; it does not project fields, coerce the payload, or run the action's journal lifecycle. The handler must complete synchronously and must not retain or mutate the payload or context.

type Route

type Route struct {
	EventName    string
	SinkName     string
	Position     compiler.Position
	SinkPosition compiler.Position
}

Route is one explicit, single-destination NFlow event route.

func RoutesFromMeta

func RoutesFromMeta(meta map[string]any) []Route

RoutesFromMeta returns the immutable route declarations parsed from @events.

Jump to

Keyboard shortcuts

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