Documentation
¶
Index ¶
- Variables
- func Emit(topic string, args ...interface{})
- func HasSlot(topic string) bool
- func Slot(topic string, fn interface{}) error
- func SlotAsync(topic string, fn interface{}, transactional bool) error
- func SlotOnce(topic string, fn interface{}) error
- func SlotOnceAsync(topic string, fn interface{}) error
- func Unslot(topic string, handler interface{}) error
- func WaitAsync()
- type Bus
- type Controller
- type Emitter
- type GenericBus
- type GenericEventBus
- func (bus *GenericEventBus[T]) Emit(topic string, data T)
- func (bus *GenericEventBus[T]) HasSlot(topic string) bool
- func (bus *GenericEventBus[T]) Slot(topic string, handler func(T))
- func (bus *GenericEventBus[T]) SlotAsync(topic string, handler func(T), transactional bool)
- func (bus *GenericEventBus[T]) SlotOnce(topic string, handler func(T))
- func (bus *GenericEventBus[T]) SlotOnceAsync(topic string, handler func(T))
- func (bus *GenericEventBus[T]) Unslot(topic string, handler func(T)) bool
- func (bus *GenericEventBus[T]) WaitAsync()
- type Slotter
- type StandardBus
- type StandardEventBus
- func (bus *StandardEventBus) Emit(topic string, args ...interface{})
- func (bus *StandardEventBus) HasSlot(topic string) bool
- func (bus *StandardEventBus) Slot(topic string, fn interface{}) error
- func (bus *StandardEventBus) SlotAsync(topic string, fn interface{}, transactional bool) error
- func (bus *StandardEventBus) SlotOnce(topic string, fn interface{}) error
- func (bus *StandardEventBus) SlotOnceAsync(topic string, fn interface{}) error
- func (bus *StandardEventBus) Unslot(topic string, fn interface{}) error
- func (bus *StandardEventBus) WaitAsync()
Constants ¶
This section is empty.
Variables ¶
var ( // GlobalBus global event bus GlobalBus = New() )
global event bus instance
Functions ¶
func SlotOnceAsync ¶
SlotOnceAsync use global bus to register once asynchronous event handler
Types ¶
type Bus ¶
type Bus interface {
Controller
Slotter
Emitter
}
Bus englobes global (slot, emit, control) bus behavior
type Controller ¶
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