closing now properly the connection

nats
Paulo Simão 2021-10-07 07:48:15 +00:00
parent 23d1d9dd1d
commit c4e964e115
1 changed files with 4 additions and 2 deletions

View File

@ -56,7 +56,7 @@ func (p *PSCli) GetConn() *websocket.Conn {
p.con = con p.con = con
p.con.SetCloseHandler(func(code int, text string) error { p.con.SetCloseHandler(func(code int, text string) error {
log.Printf("Connection closed: %d: %s", code, text) log.Printf("Connection closed: %d: %s", code, text)
p.con = nil p.Close()
return nil return nil
}) })
break break
@ -98,7 +98,9 @@ func (p *PSCli) Read(i interface{}) error {
func (p *PSCli) Close() error { func (p *PSCli) Close() error {
if !p.closed { if !p.closed {
p.closed = true p.closed = true
if p.ch != nil {
close(p.ch) close(p.ch)
}
return p.con.Close() return p.con.Close()
} }
return nil return nil