Skip to content

Commit

Permalink
del waitTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh committed Feb 13, 2020
1 parent fa58bad commit c439520
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"fmt"
"sync"
"time"
log "github.com/sirupsen/logrus"
//"reflect"
)
var (
MaxActiveConnReached = errors.New("MaxActiveConnReached")
GetConnTimeOut = errors.New("GetConnTimeOut")
)
// Config 连接池相关配置
type Config struct {
Expand Down Expand Up @@ -63,6 +64,7 @@ func NewChannelPool(poolConfig *Config) (Pool, error) {
idleTimeout: poolConfig.IdleTimeout,
waitTimeOut: poolConfig.WaitTimeOut,
maxActive: poolConfig.MaxCap,
openingConns:poolConfig.InitialCap,
}

if poolConfig.Ping != nil {
Expand Down Expand Up @@ -95,7 +97,6 @@ func (c *channelPool) Get() (interface{}, error) {
if conns == nil {
return nil, ErrClosed
}
timeOut := time.After(c.waitTimeOut)
for {
select {
case wrapConn := <-conns:
Expand All @@ -118,10 +119,9 @@ func (c *channelPool) Get() (interface{}, error) {
}
}
return wrapConn.conn, nil
case <-timeOut:
return nil, GetConnTimeOut
default:
c.mu.Lock()
log.Debugf("openConn %v %v",c.openingConns,c.maxActive)
defer c.mu.Unlock()
if c.openingConns >= c.maxActive {
return nil ,MaxActiveConnReached
Expand Down Expand Up @@ -202,6 +202,7 @@ func (c *channelPool) Release() {

close(conns)
for wrapConn := range conns {
//log.Printf("Type %v\n",reflect.TypeOf(wrapConn.conn))
closeFun(wrapConn.conn)
}
}
Expand Down

0 comments on commit c439520

Please sign in to comment.