Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,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 @@ -226,11 +231,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 @@ -214,7 +214,7 @@ func TestClientOnDisconnect(t *testing.T) {
}

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

c := NewClient(urlPath)
Expand All @@ -226,10 +226,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