You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lntop/network/backend/pool/conn.go

38 lines
498 B
Go

package pool
import (
"time"
"google.golang.org/grpc"
)
// Conn is the wrapper for a grpc client conn.
type Conn struct {
*grpc.ClientConn
pool *Pool
usedAt time.Time
}
func (c *Conn) Close() error {
if c == nil {
return nil
}
if c.ClientConn == nil {
return ErrAlreadyClosed
}
if c.pool.IsClosed() {
return ErrClosed
}
conn := Conn{
pool: c.pool,
ClientConn: c.ClientConn,
}
select {
case c.pool.conns <- conn:
default:
return ErrFullPool
}
return nil
}