EventBus is a lightweight, type-safe event dispatching library for Go. It allows registering listeners for specific event types and dispatching events in a structured, concurrency-safe way.
- Type-matching listeners using
reflect.Type - Supports multi-parameter listener functions
- Safe event dispatching via locking
- Optional debug logging using
slog - Lightweight and dependency-free
go get github.com/yourusername/eventCreates a new event bus with the given name.
Sets an optional logger for debug output.
Unlocks the bus, preventing further listener registration and allowing event dispatching.
Registers a listener function. Panics if registration fails.
Safe variant of Listen that returns an error instead of panicking.
Dispatches an event. Only listeners matching the event type will be invoked.
- Listeners can be multi-parameter functions; they will be triggered only when all required event types have been received.
- The event bus must be unlocked before sending events. Listener registration is disabled afterward to ensure consistency.
MIT