From 5eabf96e121eed91b467010c914da8a57e73432e Mon Sep 17 00:00:00 2001 From: Tobias Urdin Date: Thu, 23 Feb 2023 22:02:03 +0000 Subject: [PATCH] Call OnConnect after a connection regardless of events See: https://github.com/r3labs/sse/pull/151 --- client.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 78c936e..4bfb280 100644 --- a/client.go +++ b/client.go @@ -208,6 +208,11 @@ func (c *Client) startReadLoop(reader *EventStreamReader) (chan *Event, chan err } func (c *Client) readLoop(reader *EventStreamReader, outCh chan *Event, erChan chan error) { + if !c.Connected && c.connectedcb != nil { + c.Connected = true + c.connectedcb(c) + } + for { // Read each new line and process the type of event event, err := reader.ReadEvent() @@ -221,11 +226,6 @@ func (c *Client) readLoop(reader *EventStreamReader, outCh chan *Event, erChan c return } - if !c.Connected && c.connectedcb != nil { - c.Connected = true - c.connectedcb(c) - } - // If we get an error, ignore it. var msg *Event if msg, err = c.processEvent(event); err == nil {