Use sync.Once instead of bool flag
This commit is contained in:
parent
e068b65c78
commit
1d3eeaacf9
13
grace.go
13
grace.go
@ -59,15 +59,12 @@ type deadliner interface {
|
||||
// Allows for us to notice when the connection is closed.
|
||||
type conn struct {
|
||||
net.Conn
|
||||
wg *sync.WaitGroup
|
||||
closed bool
|
||||
wg *sync.WaitGroup
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func (c *conn) Close() error {
|
||||
if !c.closed {
|
||||
c.closed = true
|
||||
defer c.wg.Done()
|
||||
}
|
||||
func (c conn) Close() error {
|
||||
c.once.Do(func() { c.wg.Done() })
|
||||
return c.Conn.Close()
|
||||
}
|
||||
|
||||
@ -137,7 +134,7 @@ func (l *listener) Accept() (net.Conn, error) {
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &conn{Conn: c, wg: &l.wg}, nil
|
||||
return conn{Conn: c, wg: &l.wg}, nil
|
||||
}
|
||||
|
||||
type Process struct {
|
||||
|
Loading…
Reference in New Issue
Block a user