diff --git a/router/websocket/listeners.go b/router/websocket/listeners.go index b1a99ac..3a2c10f 100644 --- a/router/websocket/listeners.go +++ b/router/websocket/listeners.go @@ -26,9 +26,9 @@ func (h *Handler) ListenForExpiration(ctx context.Context) { jwt := h.GetJwt() if jwt != nil { if jwt.ExpirationTime.Unix()-time.Now().Unix() <= 0 { - h.SendJson(&Message{Event: TokenExpiredEvent}) + _ = h.SendJson(&Message{Event: TokenExpiredEvent}) } else if jwt.ExpirationTime.Unix()-time.Now().Unix() <= 180 { - h.SendJson(&Message{Event: TokenExpiringEvent}) + _ = h.SendJson(&Message{Event: TokenExpiringEvent}) } } } @@ -63,7 +63,7 @@ func (h *Handler) ListenForServerEvents(ctx context.Context) { close(eventChannel) default: - h.SendJson(&Message{ + _ = h.SendJson(&Message{ Event: d.Topic, Args: []string{d.Data}, }) diff --git a/server/events.go b/server/events.go index 71da55b..703179d 100644 --- a/server/events.go +++ b/server/events.go @@ -46,30 +46,32 @@ func (s *Server) Events() *EventBus { // Publish data to a given topic. func (e *EventBus) Publish(topic string, data string) { - e.RLock() - defer e.RUnlock() + go func() { + e.RLock() + defer e.RUnlock() - t := topic - // Some of our topics for the socket support passing a more specific namespace, - // such as "backup completed:1234" to indicate which specific backup was completed. - // - // In these cases, we still need to the send the event using the standard listener - // name of "backup completed". - if strings.Contains(topic, ":") { - parts := strings.SplitN(topic, ":", 2) + t := topic + // Some of our topics for the socket support passing a more specific namespace, + // such as "backup completed:1234" to indicate which specific backup was completed. + // + // In these cases, we still need to the send the event using the standard listener + // name of "backup completed". + if strings.Contains(topic, ":") { + parts := strings.SplitN(topic, ":", 2) - if len(parts) == 2 { - t = parts[0] + if len(parts) == 2 { + t = parts[0] + } } - } - if ch, ok := e.subscribers[t]; ok { - go func(data Event, cs []chan Event) { - for _, channel := range cs { + if ch, ok := e.subscribers[t]; ok { + data := Event{Data: data, Topic: topic} + + for _, channel := range ch { channel <- data } - }(Event{Data: data, Topic: topic}, ch) - } + } + }() } func (e *EventBus) PublishJson(topic string, data interface{}) error {