Skip to content

Commit

Permalink
lint after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminjkraft committed Aug 16, 2024
1 parent b32d4d9 commit 65b9ba9
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions graphql/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ const (
type webSocketClient struct {
Dialer Dialer
Header http.Header
endpoint string
conn WSConn
isClosing bool
errChan chan error
endpoint string
subscriptions subscriptionMap
isClosing bool
sync.Mutex
}

Expand Down Expand Up @@ -96,27 +96,27 @@ func (w *webSocketClient) waitForConnAck() error {
return nil
}

func (w *webSocketClient) handleErr(err error) {
w.Lock()
defer w.Unlock()
if !w.isClosing {
w.errChan <- err
}
}

func (w *webSocketClient) listenWebSocket() {
for {
if w.isClosing {
return
}
_, message, err := w.conn.ReadMessage()
if err != nil {
w.Lock()
defer w.Unlock()
if !w.isClosing {
w.errChan <- err
}
w.handleErr(err)
return
}
err = w.forwardWebSocketData(message)
if err != nil {
w.Lock()
defer w.Unlock()
if !w.isClosing {
w.errChan <- err
}
w.handleErr(err)
return
}
}
Expand Down Expand Up @@ -182,7 +182,10 @@ func (w *webSocketClient) Close() error {
if err != nil {
return fmt.Errorf("failed to send closure message: %w", err)
}
w.UnsubscribeAll()
err = w.UnsubscribeAll()
if err != nil {
return fmt.Errorf("failed to unsubscribe: %w", err)
}
w.Lock()
defer w.Unlock()
w.isClosing = true
Expand Down

0 comments on commit 65b9ba9

Please sign in to comment.