Skip to content

feat: add AutoReconnect option #145

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

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ type Client struct {
mu sync.Mutex
EncodingBase64 bool
Connected bool
AutoReconnect bool
}

// NewClient creates a new client
func NewClient(url string, opts ...func(c *Client)) *Client {
c := &Client{
URL: url,
Connection: &http.Client{},
AutoReconnect: false,
Headers: make(map[string]string),
subscribed: make(map[chan *Event]chan struct{}),
maxBufferSize: 1 << 16,
Expand Down Expand Up @@ -214,8 +216,10 @@ func (c *Client) readLoop(reader *EventStreamReader, outCh chan *Event, erChan c
event, err := reader.ReadEvent()
if err != nil {
if err == io.EOF {
erChan <- nil
return
if !c.AutoReconnect {
erChan <- nil
return
}
}
// run user specified disconnect function
if c.disconnectcb != nil {
Expand Down