pool

package
v1.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2020 License: Apache-2.0 Imports: 5 Imported by: 105

Documentation

Overview

通用资源池,动态增加资源实例,并支持空闲资源定时回收功能。

Index

Constants

View Source
const (
	GC_TIME = 60e9
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory func() (Src, error)

创建资源的方法

type Pool

type Pool interface {
	// 调用资源池中的资源
	Call(func(Src) error) error
	// 销毁资源池
	Close()
	// 返回当前资源数量
	Len() int
}

资源池(应设置最大容量)

func ClassicPool

func ClassicPool(capacity, maxIdle int, factory Factory, gctime ...time.Duration) Pool

构建经典资源池

type Src

type Src interface {
	// 判断资源是否可用
	Usable() bool
	// 使用后的重置方法
	Reset()
	// 被资源池删除前的自毁方法
	Close()
}

资源接口

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL