Documentation ¶
Index ¶
- Variables
- func SetActive(active uint64) options.Option
- func SetIdle(idle uint64) options.Option
- func SetIdleTimeout(idleTimeout time.Duration) options.Option
- func SetWait(wait bool, waitTimeout time.Duration) options.Option
- type IShutdown
- type List
- func (l *List) Get(ctx context.Context) (IShutdown, error)
- func (l *List) Init(d time.Duration)
- func (l *List) New(f func(ctx context.Context) (IShutdown, error))
- func (l *List) Put(ctx context.Context, s IShutdown, forceClose bool) error
- func (l *List) Reload(options ...options.Option)
- func (l *List) Shutdown() error
- func (l *List) Timer(d time.Duration)
- type Pool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func SetIdleTimeout ¶
SetIdleTimeout 设置空闲等待时间
Types ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
List 双向链表
func (*List) Get ¶
Get 获取
Example ¶
v, err := pool.Get(context.TODO()) if err != nil { // 处理错误 } // v 获取到的资源 _ = v
Output:
func (*List) Put ¶
Put 回收
Example ¶
v, err := pool.Get(context.TODO()) if err != nil { // 处理错误 } // Put: 资源回收 // forceClose: true 内部帮你调用 Shutdown回收, 否则判断是否是可回收,挂载到list上 err = pool.Put(context.TODO(), v, false) if err != nil { // 处理错误 }
Output:
type Pool ¶
type Pool interface { New(f func(ctx context.Context) (IShutdown, error)) Get(ctx context.Context) (IShutdown, error) Put(ctx context.Context, c IShutdown, forceClose bool) error Shutdown() error }
Pool interface.
func NewList ¶
NewList 实例化
Example ¶
// NewList(options ...) // 默认配置 // pool = NewList() // 可供选择配置选项 // 设置 Pool 连接数, 如果 == 0 则无限制 // SetActive(100) // 设置最大空闲连接数 // SetIdle(20) // 设置空闲等待时间 // SetIdleTimeout(time.Second) // 设置期望等待 // SetWait(false,time.Second) // 自定义配置 pool = NewList( SetActive(100), SetIdle(20), SetIdleTimeout(time.Second), SetWait(false, time.Second)) // New需要实例化,否则在 pool.Get() 会无法获取到资源 pool.New(getResources)
Output:
Click to show internal directories.
Click to hide internal directories.