Skip to content

Commit

Permalink
Merge pull request #35 from limiu82214/nim_fix_stopch
Browse files Browse the repository at this point in the history
fix the stopCh not working
  • Loading branch information
alplabin authored Aug 23, 2024
2 parents 3c78c2e + 9b7451f commit 695f92b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,26 @@ var wsServe = func(cfg *WsConfig, handler WsHandler, errHandler ErrHandler) (don
// operation.
silent := false
go func() {
select {
case <-stopCh:
silent = true
case <-doneCh:
for {
_, message, err := c.ReadMessage()
if err != nil {
if !silent {
errHandler(err)
}
stopCh <- struct{}{}
return
}
handler(message)
}
}()

for {
_, message, err := c.ReadMessage()
if err != nil {
if !silent {
errHandler(err)
}
select {
case <-stopCh:
silent = true
return
case <-doneCh:
}
handler(message)
}
}()
return
Expand Down

0 comments on commit 695f92b

Please sign in to comment.