diff --git a/constants.go b/constants.go index e9e1089..dc43ef3 100644 --- a/constants.go +++ b/constants.go @@ -1,8 +1,11 @@ package grpc_pool const ( + DefaultMaxCapacity = 1 + DefaultMaxIdle = 1 // DefaultWriteTimeout is default value of Write Timeout DefaultIdleTimeout = 0 - DefaultMaxIdle = 0 - DefaultMaxCapacity = 1 + // If Wait is true and the pool is at the MaxActive limit, then Get() waits + // for a connection to be returned to the pool before returning. + DefaultWait = false ) diff --git a/pool.go b/pool.go index e05e7c7..d51fbbc 100644 --- a/pool.go +++ b/pool.go @@ -41,12 +41,12 @@ type pool struct { stopWg sync.WaitGroup } -func New(ph PoolHandler) (Pool, error) { +func New(ph PoolHandler) Pool { p := &pool{ ph: ph, } - return p, nil + return p } func (p *pool) Start() error { diff --git a/pool_handler.go b/pool_handler.go index fe50fd8..bc2e771 100644 --- a/pool_handler.go +++ b/pool_handler.go @@ -9,8 +9,8 @@ import ( type PoolHandler interface { Dial() (conn *grpc.ClientConn, client interface{}, err error) - GetIdleTimeout() time.Duration - GetMaxIdle() int GetMaxCapacity() int + GetMaxIdle() int + GetIdleTimeout() time.Duration Validate() } diff --git a/pool_handlers.go b/pool_handlers.go index f44e7b8..539b0fd 100644 --- a/pool_handlers.go +++ b/pool_handlers.go @@ -9,23 +9,29 @@ import ( // Options is configuration of the Pool of GRpc client type PoolHandlers struct { - IdleTimeout time.Duration - MaxIdle int MaxCapacity int + MaxIdle int + IdleTimeout time.Duration + // If Wait is true and the pool is at the MaxActive limit, then Get() waits + // for a connection to be returned to the pool before returning. + Wait bool } func (ph *PoolHandlers) Dial() (*grpc.ClientConn, interface{}, error) { return nil, nil, fmt.Errorf("GRPC Pool: Dial method is not implemented") } -func (ph *PoolHandlers) GetIdleTimeout() time.Duration { - return ph.IdleTimeout +func (ph *PoolHandlers) GetMaxCapacity() int { + return ph.MaxCapacity } func (ph *PoolHandlers) GetMaxIdle() int { return ph.MaxIdle } -func (ph *PoolHandlers) GetMaxCapacity() int { - return ph.MaxCapacity +func (ph *PoolHandlers) GetIdleTimeout() time.Duration { + return ph.IdleTimeout +} +func (ph *PoolHandlers) IsWait() bool { + return ph.Wait } // Validate validates the configuration