Documentation
¶
Overview ¶
Package banji provides a concurrent proactor and a framework for implementing EDA.
Index ¶
- Constants
- type Bus
- type Component
- type Engine
- type ErrorEvent
- type Event
- type EventEmbed
- type Level
- type Log
- func (l *Log) Add(k string, v any) *Log
- func (l *Log) Data() LogData
- func (l *Log) Description() string
- func (l *Log) ID() uuid.UUID
- func (l *Log) Kind() string
- func (l *Log) Level() Level
- func (l *Log) MarshalJSON() ([]byte, error)
- func (l *Log) Postmark() time.Time
- func (l *Log) Value(key string) any
- func (l *Log) With(x ...any) error
- type LogData
- type LogEvent
- type LogField
- type Option
- type Options
- type PostTickEvent
- type PreTickEvent
- type Receiver
- type ReceiverEmbed
- type StartEvent
- type StopEvent
Constants ¶
const ErrorTopic = "banji.error"
const LogTopic = "banji.log"
const PostTickTopic = "banji.postTick"
const PreTickTopic = "banji.preTick"
const StartTopic = "banji.start"
const StopTopic = "banji.stopLoop"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus interface { Tick() Subscribe(r Receiver) Unsubscribe(r Receiver) Post(event Event, priority uint8) Size() int }
A Bus is an entity that can receive and route Event types to Receiver types.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
The Engine brokers communication between decoupled components via Event and Receiver.
func (*Engine) Post ¶
Post posts an Event to the engine. The Event will be handled on the next tick.
func (*Engine) Start ¶
func (eng *Engine) Start()
Start starts the engine. Start is a non-blocking operation.
Receivers can subscribe to StartTopic to listen for this operation.
func (*Engine) Stop ¶
func (eng *Engine) Stop()
Stop gracefully shuts down the engine, and thus, is a blocking operation.
Receivers can subscribe to StopTopic to listen for this operation.
func (*Engine) Unsubscribe ¶
Unsubscribe unregisters a Receiver. Note that this can be an expensive operation, and thus it should be used sparingly.
type ErrorEvent ¶
type ErrorEvent struct { EventEmbed // contains filtered or unexported fields }
ErrorEvent is an Event posted when a Receiver's handler method returns an error.
func (*ErrorEvent) Error ¶
func (e *ErrorEvent) Error() error
func (*ErrorEvent) Topic ¶
func (e *ErrorEvent) Topic() string
type Event ¶
type Event interface { ID() uuid.UUID Postmark() time.Time Topic() string Cancel() Canceled() bool // contains filtered or unexported methods }
An Event is any type that can be emitted and routed by the engine.
type EventEmbed ¶
type EventEmbed struct {
// contains filtered or unexported fields
}
EventEmbed contains internal methods required to implement the Event interface.
func (*EventEmbed) Cancel ¶
func (e *EventEmbed) Cancel()
func (*EventEmbed) Canceled ¶
func (e *EventEmbed) Canceled() bool
func (*EventEmbed) ID ¶
func (e *EventEmbed) ID() uuid.UUID
func (*EventEmbed) Postmark ¶
func (e *EventEmbed) Postmark() time.Time
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
func (*Log) Description ¶
func (*Log) MarshalJSON ¶
type LogEvent ¶
type LogEvent struct { EventEmbed // contains filtered or unexported fields }
LogEvent is an Event posted when a log message is created.
func NewLogEvent ¶
type Options ¶
func NewOptions ¶
type PostTickEvent ¶
type PostTickEvent struct { EventEmbed // contains filtered or unexported fields }
PostTickEvent is an Event posted once the work for a given tick has concluded. Therefore, it does not necessarily mean that a new tick has also begun (you should listen for PreTickEvent instead for such purposes).
func (*PostTickEvent) Tick ¶
func (e *PostTickEvent) Tick() time.Time
func (*PostTickEvent) Topic ¶
func (e *PostTickEvent) Topic() string
type PreTickEvent ¶
type PreTickEvent struct { EventEmbed // contains filtered or unexported fields }
PreTickEvent is an Event posted when a new tick has begun.
func (*PreTickEvent) Tick ¶
func (e *PreTickEvent) Tick() time.Time
func (*PreTickEvent) Topic ¶
func (e *PreTickEvent) Topic() string
type Receiver ¶
type Receiver interface { ID() uuid.UUID Postmark() time.Time Topic() string Handle(event Event) error // contains filtered or unexported methods }
A Receiver is any type that can receive and handle Event types.
type ReceiverEmbed ¶
type ReceiverEmbed struct {
// contains filtered or unexported fields
}
ReceiverEmbed contains internal methods required to implement the Receiver interface.
func (*ReceiverEmbed) ID ¶
func (r *ReceiverEmbed) ID() uuid.UUID
func (*ReceiverEmbed) Postmark ¶
func (r *ReceiverEmbed) Postmark() time.Time
type StartEvent ¶
type StartEvent struct {
EventEmbed
}
StartEvent is an Event posted when the Engine starts. It primarily serves as a signal to components to perform any bootstrapping or initialization they may require.
func (*StartEvent) Topic ¶
func (e *StartEvent) Topic() string
type StopEvent ¶
type StopEvent struct {
EventEmbed
}
StopEvent is an Event posted when the engine is about to shut down. It primarily serves as a signal to components to perform any shutdown or cleanup mechanics they may require. StopEvent should not be used as a catalyst for posting additional events, as they will not be routed by the engine once StopEvent has been posted.