对象复用类

package
v0.0.0-...-fcd50c7 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

包gpool提供了对象可重用的并发安全池。 md5:d111530cd572ede7

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpireFunc

type ExpireFunc func(interface{})

ExpireFunc 对象的销毁函数。 md5:cd0e3912eae30a98

type NewFunc

type NewFunc func() (interface{}, error)

NewFunc 对象的创建函数。 md5:245f622ac151f3ff

type Pool

type Pool struct {
	TTL     time.Duration               // 对象池中项目的生存时间。 md5:d9c944077d869281
	NewFunc func() (interface{}, error) // 创建池项的回调函数。 md5:f37bfc92a2188739
	// ExpireFunc 是用于过期项目销毁的函数。
	// 当池中的项目需要执行额外销毁操作时,需要定义这个函数。
	// 例如:net.Conn、os.File 等。
	// md5:f09911de2780aeaa
	ExpireFunc func(interface{})
	// contains filtered or unexported fields
}

Pool是一个对象可重用池。 md5:08c256ba80594199

func X创建

func X创建(过期时长 time.Duration, 新创建回调函数 NewFunc, 过期销毁回调函数 ...ExpireFunc) *Pool

X创建 创建并返回一个新的对象池。 为了确保执行效率,一旦设置,过期时间将不能修改。

注意过期逻辑: ttl = 0:未过期; ttl < 0:使用后立即过期; ttl > 0:超时过期。 md5:9f724382dd2313e7

func (*Pool) X入栈

func (p *Pool) X入栈(对象 interface{}) error

X入栈 将一个项目放入池中。 md5:d7b57780f7e8f1cc

func (*Pool) X入栈PANI

func (p *Pool) X入栈PANI(对象 interface{})

X入栈PANI 将一个项目放入池中,如果发生任何错误,它将引发恐慌。 md5:10206f4587a99039

func (*Pool) X关闭

func (p *Pool) X关闭()

X关闭 关闭池。如果 `p` 有 ExpireFunc,那么在关闭之前,它会自动使用这个函数关闭所有项目。通常情况下,你不需要手动调用这个函数。 md5:368c18d44115f9cc

func (*Pool) X出栈

func (p *Pool) X出栈() (interface{}, error)

X出栈 从池中选取并返回一个项目。如果池是空的并且已定义了NewFunc, 则会使用NewFunc创建并返回一个项目。 md5:7782b49d380b807b

func (*Pool) X取数量

func (p *Pool) X取数量() int

X取数量 返回池中可用项目的数量。 md5:2b8a683e177e1586

func (*Pool) X清空

func (p *Pool) X清空()

X清空 清空池子,这意味着它将从池中移除所有项目。 md5:c141b6e6c215bc68

Jump to

Keyboard shortcuts

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