contract

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RegisteredListenerSourceListener   = "listener"
	RegisteredListenerSourceSubscriber = "subscriber"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {
	Name() string

	Payload() any

	Timestamp() time.Time

	StopPropagation()

	IsPropagationStopped() bool
}

type EventDispatcher

type EventDispatcher interface {
	AddListener(eventName string, listener EventListener, priority int) ListenerRegistration

	RemoveListener(registration ListenerRegistration) bool

	AddSubscriber(subscriber EventSubscriber)

	RemoveSubscriber(subscriber EventSubscriber) int

	/* Dispatch runs the listeners registered for the event's name in descending priority order. The first listener error aborts the remaining listeners and is returned alongside the (partially dispatched) event; callers decide the policy for partial dispatch. */
	Dispatch(runtimeInstance runtimecontract.Runtime, event Event) (Event, error)

	/* DispatchName behaves like Dispatch for the given event name and payload: listeners run in descending priority order and the first listener error aborts the remaining listeners. */
	DispatchName(runtimeInstance runtimecontract.Runtime, eventName string, payload any) (Event, error)
}

type EventDispatcherInspector

type EventDispatcherInspector interface {
	RegisteredEvents() []RegisteredEvent
}

type EventListener

type EventListener func(runtimeInstance runtimecontract.Runtime, event Event) error

type EventSubscriber

type EventSubscriber interface {
	SubscribedEvents() map[string][]SubscribedEvent
}

type ListenerRegistration

type ListenerRegistration struct {
	EventName  string
	ListenerId uint64
}

type RegisteredEvent

type RegisteredEvent struct {
	EventName string               `json:"eventName"`
	Listeners []RegisteredListener `json:"listeners"`
}

type RegisteredListener

type RegisteredListener struct {
	Priority     int    `json:"priority"`
	Source       string `json:"source"`
	Owner        string `json:"owner"`
	ListenerId   string `json:"listenerId"`
	ListenerName string `json:"listenerName"`
}

type RequiredListenerRegistrar added in v1.15.0

type RequiredListenerRegistrar interface {
	MarkListenerRequired(registration ListenerRegistration)

	MarkListenerMaySkipRequiredListeners(registration ListenerRegistration)
}

RequiredListenerRegistrar is an optional interface an EventDispatcher may implement to mark registered listeners as required. When a listener stops event propagation before a required listener behind it (lower priority) has run, Dispatch/DispatchName return an error instead of silently completing, so a caller such as the http kernel fails closed rather than proceeding as if the required listener — for example the security access-control listener — had run. A listener that legitimately short-circuits past required listeners opts out through MarkListenerMaySkipRequiredListeners. Both marks default off, so a dispatcher and its callers behave exactly as before unless a listener is explicitly marked; the first listener error already aborts dispatch regardless.

type SubscribedEvent

type SubscribedEvent interface {
	Listener() EventListener

	Priority() int
}

Jump to

Keyboard shortcuts

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