event

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface {
	EventName() string    // Returns the name of the event (e.g., "UserCreated")
	EventID() string      // Returns a unique ID for this specific event instance
	Timestamp() time.Time // Returns the time when the event occurred

}

Event is the base interface for all domain events.

type EventBus

type EventBus interface {
	Publisher
	Subscriber
	// 如果事件总线是后台进程,可以添加 Start 和 Stop 方法来管理其生命周期
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

EventBus combines publishing and subscribing capabilities.

type EventHandler

type EventHandler func(ctx context.Context, event Event) error

EventHandler is a function type that handles a specific event.

type Publisher

type Publisher interface {
	Publish(ctx context.Context, event Event) error
}

Publisher is an interface for publishing events.

type Subscriber

type Subscriber interface {
	Subscribe(ctx context.Context, eventName string, handler EventHandler) error
	Unsubscribe(ctx context.Context, eventName string, handler EventHandler) error
}

Subscriber is an interface for subscribing to events.

Jump to

Keyboard shortcuts

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