Fix WebSocket close
This commit is contained in:
parent
70b3dbf548
commit
fc574ac209
2 changed files with 14 additions and 3 deletions
|
@ -66,6 +66,7 @@ func (c *WSClient) streamingWS(ctx context.Context, stream, tag string) (chan Ev
|
|||
|
||||
q := make(chan Event)
|
||||
go func() {
|
||||
defer close(q)
|
||||
for {
|
||||
err := c.handleWS(ctx, u.String(), q)
|
||||
if err != nil {
|
||||
|
@ -85,7 +86,12 @@ func (c *WSClient) handleWS(ctx context.Context, rawurl string, q chan Event) er
|
|||
// End.
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// Close the WebSocket when the context is canceled.
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
conn.Close()
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue