event

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package event provides a lightweight in-process event bus and queue, modeled on kitex's pkg/event. It decouples producers from consumers: for example, a service-discovery cache can dispatch a "discovery.change" event that a circuit-breaker suite subscribes to in order to evict state for removed instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus interface {
	// Watch registers cb for events named name.
	Watch(name string, cb Callback)
	// Unwatch removes a previously registered cb.
	Unwatch(name string, cb Callback)
	// Dispatch delivers e to all callbacks watching its name.
	Dispatch(e *Event)
}

Bus dispatches named events to registered callbacks.

func NewBus

func NewBus() Bus

NewBus returns an empty Bus.

type Callback

type Callback func(*Event)

Callback handles a dispatched event.

type Event

type Event struct {
	Name string
	Data any
}

Event is a named payload delivered on a Bus.

type Queue

type Queue interface {
	// Push appends an event, dropping the oldest when capacity is exceeded.
	Push(e *Event)
	// Dump returns a snapshot of the buffered events.
	Dump() []*Event
}

Queue is a bounded event buffer that retains the most recent events.

func NewQueue

func NewQueue(capacity int) Queue

NewQueue returns a Queue with the given capacity. A capacity <= 0 means unbounded.

Jump to

Keyboard shortcuts

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