eventbus

package
v1.8.5 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GlobalBus global event bus
	GlobalBus = New()
)

global event bus instance

Functions

func Emit

func Emit(topic string, args ...interface{})

Emit use global bus to emit event

func HasSlot

func HasSlot(topic string) bool

HasSlot use global bus to check if there is a handler

func Slot

func Slot(topic string, fn interface{}) error

Slot use global bus to register event handler

func SlotAsync

func SlotAsync(topic string, fn interface{}, transactional bool) error

SlotAsync use global bus to register asynchronous event handler

func SlotOnce

func SlotOnce(topic string, fn interface{}) error

SlotOnce use global bus to register once event handler

func SlotOnceAsync

func SlotOnceAsync(topic string, fn interface{}) error

SlotOnceAsync use global bus to register once asynchronous event handler

func Unslot

func Unslot(topic string, handler interface{}) error

Unslot use global bus to remove event handler

func WaitAsync

func WaitAsync()

WaitAsync use global bus to wait for asynchronous processing to complete

Types

type Bus

type Bus interface {
	Controller
	Slotter
	Emitter
}

Bus englobes global (slot, emit, control) bus behavior

func New

func New() Bus

New create a new event bus instance

type Controller

type Controller interface {
	HasSlot(topic string) bool
	WaitAsync()
}

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

type Emitter

type Emitter interface {
	Emit(topic string, args ...interface{})
}

Emitter defines emission-related bus behavior

type GenericBus

type GenericBus[T any] interface {
	// Slot register event handler
	Slot(topic string, handler func(T))
	// SlotAsync 注册异步事件处理器
	SlotAsync(topic string, handler func(T), transactional bool)
	// SlotOnce register once event handler
	SlotOnce(topic string, handler func(T))
	// SlotOnceAsync register once asynchronous event handler
	SlotOnceAsync(topic string, handler func(T))
	// Emit emit event
	Emit(topic string, data T)
	// Unslot remove event handler
	Unslot(topic string, handler func(T)) bool
	// HasSlot check if there is a handler
	HasSlot(topic string) bool
	// WaitAsync wait for asynchronous processing to complete
	WaitAsync()
}

GenericBus generic event bus interface

func NewGeneric

func NewGeneric[T any]() GenericBus[T]

NewGeneric create generic event bus instance

type GenericEventBus

type GenericEventBus[T any] struct {
	// contains filtered or unexported fields
}

GenericEventBus generic event bus implementation

func (*GenericEventBus[T]) Emit

func (bus *GenericEventBus[T]) Emit(topic string, data T)

Emit emit event

func (*GenericEventBus[T]) HasSlot

func (bus *GenericEventBus[T]) HasSlot(topic string) bool

HasSlot check if there is a handler

func (*GenericEventBus[T]) Slot

func (bus *GenericEventBus[T]) Slot(topic string, handler func(T))

Slot register event handler

func (*GenericEventBus[T]) SlotAsync

func (bus *GenericEventBus[T]) SlotAsync(topic string, handler func(T), transactional bool)

SlotAsync register asynchronous event handler

func (*GenericEventBus[T]) SlotOnce

func (bus *GenericEventBus[T]) SlotOnce(topic string, handler func(T))

SlotOnce register once event handler

func (*GenericEventBus[T]) SlotOnceAsync

func (bus *GenericEventBus[T]) SlotOnceAsync(topic string, handler func(T))

SlotOnceAsync register once asynchronous event handler

func (*GenericEventBus[T]) Unslot

func (bus *GenericEventBus[T]) Unslot(topic string, handler func(T)) bool

Unslot remove event handler

func (*GenericEventBus[T]) WaitAsync

func (bus *GenericEventBus[T]) WaitAsync()

WaitAsync wait for asynchronous processing to complete

type Slotter

type Slotter interface {
	Slot(topic string, fn interface{}) error
	SlotAsync(topic string, fn interface{}, transactional bool) error
	SlotOnce(topic string, fn interface{}) error
	SlotOnceAsync(topic string, fn interface{}) error
	Unslot(topic string, handler interface{}) error
}

Slotter defines slot-related bus behavior

type StandardBus

type StandardBus interface {
	// Slot register event handler
	Slot(topic string, handler interface{}) error
	// SlotAsync register asynchronous event handler
	SlotAsync(topic string, handler interface{}, transactional bool) error
	// SlotOnce register once event handler
	SlotOnce(topic string, handler interface{}) error
	// SlotOnceAsync register once asynchronous event handler
	SlotOnceAsync(topic string, handler interface{}) error
	// Emit emit event
	Emit(topic string, args ...interface{})
	// Unslot remove event handler
	Unslot(topic string, handler interface{}) error
	// HasSlot check if there is a handler
	HasSlot(topic string) bool
	// WaitAsync wait for asynchronous processing to complete
	WaitAsync()
}

StandardBus standard event bus interface (using interface{} type)

type StandardEventBus

type StandardEventBus struct {
	// contains filtered or unexported fields
}

StandardEventBus standard event bus implementation

func (*StandardEventBus) Emit

func (bus *StandardEventBus) Emit(topic string, args ...interface{})

Emit emit event

func (*StandardEventBus) HasSlot

func (bus *StandardEventBus) HasSlot(topic string) bool

HasSlot check if there is a handler

func (*StandardEventBus) Slot

func (bus *StandardEventBus) Slot(topic string, fn interface{}) error

Slot register event handler

func (*StandardEventBus) SlotAsync

func (bus *StandardEventBus) SlotAsync(topic string, fn interface{}, transactional bool) error

SlotAsync register asynchronous event handler

func (*StandardEventBus) SlotOnce

func (bus *StandardEventBus) SlotOnce(topic string, fn interface{}) error

SlotOnce register once event handler

func (*StandardEventBus) SlotOnceAsync

func (bus *StandardEventBus) SlotOnceAsync(topic string, fn interface{}) error

SlotOnceAsync register once asynchronous event handler

func (*StandardEventBus) Unslot

func (bus *StandardEventBus) Unslot(topic string, fn interface{}) error

Unslot 移除事件处理器

func (*StandardEventBus) WaitAsync

func (bus *StandardEventBus) WaitAsync()

WaitAsync wait for asynchronous processing to complete

Jump to

Keyboard shortcuts

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