2019-07-28 20:56:18 +03:00
|
|
|
// Package pool is a connection pool
|
|
|
|
package pool
|
|
|
|
|
|
|
|
import (
|
2020-11-03 02:02:32 +03:00
|
|
|
"context"
|
2019-07-28 20:56:18 +03:00
|
|
|
"time"
|
|
|
|
|
2020-09-20 16:57:54 +03:00
|
|
|
"github.com/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
|
2020-11-03 02:02:32 +03:00
|
|
|
Get(ctx context.Context, addr string, opts ...transport.DialOption) (Conn, error)
|
2020-07-16 18:33:11 +03:00
|
|
|
// Release the connection
|
2019-07-28 20:56:18 +03:00
|
|
|
Release(c Conn, status error) error
|
|
|
|
}
|
|
|
|
|
2021-02-14 16:16:01 +03:00
|
|
|
// Conn conn pool interface
|
2019-07-28 20:56:18 +03:00
|
|
|
type Conn interface {
|
|
|
|
// unique id of connection
|
|
|
|
Id() string
|
|
|
|
// 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 20:56:18 +03:00
|
|
|
func NewPool(opts ...Option) Pool {
|
2021-02-14 16:16:01 +03:00
|
|
|
options := Options{}
|
2019-07-28 20:56:18 +03:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&options)
|
|
|
|
}
|
|
|
|
return newPool(options)
|
|
|
|
}
|