pool

package
v0.0.0-...-4a740ba Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LIFO

type LIFO struct {
	MaxItems    int64
	MinItems    int64
	MaxIdles    int64
	IdleTimeout protocol.Duration
	// New optionally specifies a function to generate
	// a value when Get would otherwise return nil.
	// It may not be changed concurrently with calls to Get.
	New func() interface{}
	// CloseFunc optionally specifies a function to call when an item want to drop after timeout
	CloseFunc func(item interface{})
	// contains filtered or unexported fields
}

LIFO pool, i.e. the most recently Put() item will return in call Get() Such a scheme keeps CPU caches hot (in theory).

Due to LIFO behaviors and MaxItems logic can't implement with sync/atomic like sync.Pool

func (*LIFO) Clean

func (p *LIFO) Clean()

Clean items but not by exact p.IdleTimeout. To improve performance we choose two window clean up. Means some idle items can live up to double of p.IdleTimeout

func (*LIFO) Close

func (p *LIFO) Close()

func (*LIFO) Get

func (p *LIFO) Get() (item interface{})

func (*LIFO) Init

func (p *LIFO) Init()

func (*LIFO) Len

func (p *LIFO) Len() (ln int)

func (*LIFO) Put

func (p *LIFO) Put(item interface{})

func (*LIFO) SetState

func (p *LIFO) SetState(state PoolStatus) (pre PoolStatus)

func (*LIFO) State

func (p *LIFO) State() PoolStatus

type PoolStatus

type PoolStatus int32
const (
	PoolStatus_Unset PoolStatus = iota
	PoolStatus_Running
	PoolStatus_Stopping
	PoolStatus_Stopped
)

Jump to

Keyboard shortcuts

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