2024-06-04 00:15:07 +07:00
|
|
|
package events
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/teivah/broadcast"
|
2024-06-10 14:52:53 +07:00
|
|
|
apievents "github.com/tigorlazuardi/redmage/api/events"
|
2024-06-04 00:15:07 +07:00
|
|
|
"github.com/tigorlazuardi/redmage/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Handler struct {
|
|
|
|
Config *config.Config
|
2024-06-10 14:52:53 +07:00
|
|
|
Broadcast *broadcast.Relay[apievents.Event]
|
2024-06-04 00:15:07 +07:00
|
|
|
}
|
|
|
|
|
2024-06-10 14:52:53 +07:00
|
|
|
func NewHandler(cfg *config.Config, broadcast *broadcast.Relay[apievents.Event]) *Handler {
|
|
|
|
return &Handler{
|
|
|
|
Config: cfg,
|
|
|
|
Broadcast: broadcast,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (handler *Handler) Subscribe() (<-chan apievents.Event, func()) {
|
2024-06-04 00:15:07 +07:00
|
|
|
listener := handler.Broadcast.Listener(10)
|
|
|
|
return listener.Ch(), listener.Close
|
|
|
|
}
|