subscribe on all events if no events type are given

This commit is contained in:
Milarin 2024-02-20 13:54:57 +01:00
parent 49708ed503
commit 075a8441cd
1 changed files with 2 additions and 1 deletions

View File

@ -16,6 +16,7 @@ func (i *Client) Subscribe(ctx context.Context, events ...EventType) (<-chan Eve
out := make(chan Event, 10)
eventMap := slices.ToStructMap(events)
allEvents := len(events) == 0
go func() {
defer r.Close()
@ -25,7 +26,7 @@ func (i *Client) Subscribe(ctx context.Context, events ...EventType) (<-chan Eve
for ctx.Err() == nil && sc.Scan() {
event := parseEvent(sc.Text())
if _, ok := eventMap[event.Type]; ok {
if _, ok := eventMap[event.Type]; allEvents || ok {
out <- event
}
}