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