event

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package event provides an in-process publish/subscribe event bus.

Handlers can be registered synchronously or asynchronously, as one-shot (once) subscriptions, and in a transactional mode that serializes async delivery. It is meant for decoupling components within a single process, not for cross-service messaging (use the kafka package for that).

Index

Constants

View Source
const (
	ErrCodeBusNotReflectType = "BUS-001"
	ErrCodeBusTopicNotExists = "BUS-002"
)

Variables

View Source
var (
	ErrBusNotReflectType = func(v reflect.Kind) error {
		return jet.NewAppErrBuilder(ErrCodeBusNotReflectType, "%s is not of type reflect.Func", v).Err()
	}
	ErrBusTopicNotExists = func(topic string) error {
		return jet.NewAppErrBuilder(ErrCodeBusTopicNotExists, "topic doesn't exists (%s)", topic).Err()
	}
)

Functions

This section is empty.

Types

type Bus

type Bus interface {
	BusController
	BusSubscriber
	BusPublisher
}

Bus is a global (subscribe, publish, control) bus behavior

func New

func New(l jet.CLoggerFunc) Bus

New returns new eventBus with empty handlers.

type BusController

type BusController interface {
	HasCallback(topic string) bool
	WaitAsync()
}

BusController defines bus control behavior (checking handler's presence, synchronization)

type BusPublisher

type BusPublisher interface {
	Publish(ctx context.Context, topic string, args ...interface{})
}

BusPublisher defines publishing-related bus behavior

type BusSubscriber

type BusSubscriber interface {
	Subscribe(topic string, fn interface{}) error
	SubscribeAsync(topic string, fn interface{}, transactional bool) error
	SubscribeOnce(topic string, fn interface{}) error
	SubscribeOnceAsync(topic string, fn interface{}) error
	Unsubscribe(topic string, handler interface{}) error
}

BusSubscriber defines subscription-related bus behavior

type Event

type Event[T any] interface {
	Register(handler func(ctx context.Context, data T) error)
	ExecuteAsync(ctx context.Context, data T)
	Execute(ctx context.Context, data T) error
	Wait()
}

func NewEventHandler

func NewEventHandler[T any](logger jet.CLoggerFunc) Event[T]

Jump to

Keyboard shortcuts

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