micro/util/pool/pool.go

39 lines
798 B
Go
Raw Permalink Normal View History

2019-07-28 20:56:18 +03:00
// Package pool is a connection pool
package pool // import "go.unistack.org/micro/v3/util/pool"
2019-07-28 20:56:18 +03:00
import (
"context"
2019-07-28 20:56:18 +03:00
"time"
"go.unistack.org/micro/v3/network/transport"
2019-07-28 20:56:18 +03:00
)
// Pool is an interface for connection pooling
type Pool interface {
// Close the pool
Close() error
// Get a connection
Get(ctx context.Context, addr string, opts ...transport.DialOption) (Conn, error)
// Release the connection
2019-07-28 20:56:18 +03:00
Release(c Conn, status error) error
}
// Conn conn pool interface
2019-07-28 20:56:18 +03:00
type Conn interface {
// unique id of connection
ID() string
2019-07-28 20:56:18 +03:00
// time it was created
Created() time.Time
// embedded connection
transport.Client
}
// NewPool creates new connection pool
2019-07-28 20:56:18 +03:00
func NewPool(opts ...Option) Pool {
options := Options{}
2019-07-28 20:56:18 +03:00
for _, o := range opts {
o(&options)
}
return newPool(options)
}