Skip to content
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
28 changes: 21 additions & 7 deletions recws.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ type RecConn struct {
// NonVerbose suppress connecting/reconnecting messages.
NonVerbose bool

isConnected bool
mu sync.RWMutex
url string
reqHeader http.Header
httpResp *http.Response
dialErr error
dialer *websocket.Dialer
isConnected bool
isConnectRunning bool
mu sync.RWMutex
url string
reqHeader http.Header
httpResp *http.Response
dialErr error
dialer *websocket.Dialer

*websocket.Conn
}
Expand Down Expand Up @@ -418,6 +419,15 @@ func (rc *RecConn) keepAlive() {
}

func (rc *RecConn) connect() {
rc.mu.Lock()
canStart := !rc.isConnectRunning
rc.isConnectRunning = true
rc.mu.Unlock()

if !canStart {
return
}

b := rc.getBackoff()
rand.Seed(time.Now().UTC().UnixNano())

Expand Down Expand Up @@ -450,6 +460,10 @@ func (rc *RecConn) connect() {
rc.keepAlive()
}

rc.mu.Lock()
rc.isConnectRunning = false
rc.mu.Unlock()

return
}

Expand Down