micro/util/pool/pool.go

39 lines
759 B
Go
Raw Normal View History

2019-07-28 20:56:18 +03:00
// Package pool is a connection pool
package pool
import (
"context"
2019-07-28 20:56:18 +03:00
"time"
"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
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
// 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)
}