Skip to content

Commit

Permalink
Apply r3labs#151
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-cheperis committed Jan 6, 2024
1 parent e0a8455 commit 81bb3f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 5 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func TestClientOnDisconnect(t *testing.T) {
}

func TestClientOnConnect(t *testing.T) {
setup(false)
newServer()
defer cleanup()

c := NewClient(urlPath)
Expand All @@ -227,10 +227,8 @@ func TestClientOnConnect(t *testing.T) {

go c.Subscribe("test", func(msg *Event) {})

time.Sleep(time.Second)
time.Sleep(time.Millisecond * 50)
assert.Equal(t, struct{}{}, <-called)

server.CloseClientConnections()
}

func TestClientChanReconnect(t *testing.T) {
Expand Down

0 comments on commit 81bb3f1

Please sign in to comment.