The OnConnect callback (added in #137) is only sent during the readLoop so it will only be triggered after the server sends an event, which could be some time (or even never) after a connection is established:
It seems the callback could and should be called here instead, directly after the HTTP response:
|
defer resp.Body.Close() |
|
|
|
reader := NewEventStreamReader(resp.Body, c.maxBufferSize) |
|
if !connected { |
|
// Notify connect |
|
errch <- nil |
|
connected = true |
|
} |
or, at the top of readLoop
The OnConnect callback (added in #137) is only sent during the
readLoopso it will only be triggered after the server sends an event, which could be some time (or even never) after a connection is established:sse/client.go
Line 231 in c6d5381
It seems the callback could and should be called here instead, directly after the HTTP response:
sse/client.go
Lines 98 to 100 in c6d5381
sse/client.go
Lines 152 to 156 in c6d5381
or, at the top of
readLoop