diff --git a/router/websocket/listeners.go b/router/websocket/listeners.go index bf872c6..124a85d 100644 --- a/router/websocket/listeners.go +++ b/router/websocket/listeners.go @@ -52,16 +52,15 @@ func (h *Handler) ListenForServerEvents(ctx context.Context) { h.server.Events().Subscribe(event, eventChannel) } - select { - case <-ctx.Done(): - for _, event := range events { - h.server.Events().Unsubscribe(event, eventChannel) - } + for d := range eventChannel { + select { + case <-ctx.Done(): + for _, event := range events { + h.server.Events().Unsubscribe(event, eventChannel) + } - close(eventChannel) - default: - // Listen for different events emitted by the server and respond to them appropriately. - for d := range eventChannel { + close(eventChannel) + default: h.SendJson(&Message{ Event: d.Topic, Args: []string{d.Data},