Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call OnConnect after a connection regardless of events #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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