Browse Source

Use a sync.Once in Conn.Close

pull/1422/head
Alex Browne 5 years ago
committed by Steven Allen
parent
commit
a4d3db5f85
  1. 5
      p2p/transport/websocket/conn_browser.go

5
p2p/transport/websocket/conn_browser.go

@ -33,6 +33,7 @@ type Conn struct {
currDataMut sync.RWMutex
currData bytes.Buffer
closeOnce sync.Once
closeSignalOnce sync.Once
closeSignal chan struct{}
dataSignal chan struct{}
localAddr net.Addr
@ -126,14 +127,16 @@ func (c *Conn) Write(b []byte) (n int, err error) {
// close error, subsequent and concurrent calls will return nil.
// This method is thread-safe.
func (c *Conn) Close() error {
c.closeOnce.Do(func() {
c.signalClose()
c.Call("close")
c.releaseHandlers()
})
return nil
}
func (c *Conn) signalClose() {
c.closeOnce.Do(func() {
c.closeSignalOnce.Do(func() {
close(c.closeSignal)
})
}

Loading…
Cancel
Save