Skip to content

Commit e4b8869

Browse files
closing
1 parent 8a982d7 commit e4b8869

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

graphql/websocket.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"reflect"
1010
"strings"
1111
"sync"
12+
"sync/atomic"
1213
"time"
1314

1415
"github.com/google/uuid"
@@ -51,7 +52,7 @@ type webSocketClient struct {
5152
connParams map[string]interface{}
5253
errChan chan error
5354
subscriptions subscriptionMap
54-
isClosing bool
55+
isClosing atomic.Bool
5556
sync.Mutex
5657
}
5758

@@ -107,14 +108,14 @@ func (w *webSocketClient) waitForConnAck() error {
107108
func (w *webSocketClient) handleErr(err error) {
108109
w.Lock()
109110
defer w.Unlock()
110-
if !w.isClosing {
111+
if !w.isClosing.Load() {
111112
w.errChan <- err
112113
}
113114
}
114115

115116
func (w *webSocketClient) listenWebSocket() {
116117
for {
117-
if w.isClosing {
118+
if w.isClosing.Load() {
118119
return
119120
}
120121
_, message, err := w.conn.ReadMessage()
@@ -208,7 +209,7 @@ func (w *webSocketClient) Close() error {
208209
}
209210
w.Lock()
210211
defer w.Unlock()
211-
w.isClosing = true
212+
w.isClosing.Store(true)
212213
close(w.errChan)
213214
return w.conn.Close()
214215
}

0 commit comments

Comments
 (0)