statepool

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package statepool holds idle Lua states in per-key buckets.

Buckets grow on demand. Acquire pops an idle state or builds one through the caller factory. Return stores the state again or closes it when the bucket already holds the configured maximum.

Index

Constants

View Source
const DefaultBucketSize = 16

DefaultBucketSize caps idle states stored per bucket.

Variables

This section is empty.

Functions

func Acquire

func Acquire(bucketKey string, createState func() *lua.LState) *lua.LState

Acquire pops an idle state for bucketKey from the shared pool or builds one with createState.

func BucketSize

func BucketSize() int

BucketSize reports the shared pool per-bucket idle limit.

func Invalidate

func Invalidate(bucketKey string)

Invalidate closes every idle state for bucketKey in the shared pool.

func InvalidateAll

func InvalidateAll()

InvalidateAll closes every idle state in the shared pool.

func Length

func Length(bucketKey string) int

Length reports idle states the shared pool stores for bucketKey.

func Return

func Return(bucketKey string, state *lua.LState)

Return stores state for bucketKey in the shared pool or closes it when the bucket is full.

func SetBucketSize

func SetBucketSize(size int)

SetBucketSize replaces the shared pool per-bucket idle limit.

Types

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool keeps idle Lua states keyed by bucket.

func NewPool

func NewPool(maximumPerBucket int) *Pool

NewPool builds an empty pool holding at most maximumPerBucket idle states per bucket. Negative values disable storage.

func (*Pool) Acquire

func (pool *Pool) Acquire(bucketKey string, createState func() *lua.LState) *lua.LState

Acquire pops an idle state for bucketKey or builds one with createState. The factory runs without holding the pool lock. A nil factory on a miss returns nil. An empty bucket key bypasses storage and always builds.

func (*Pool) BucketSize

func (pool *Pool) BucketSize() int

BucketSize reports the per-bucket idle limit.

func (*Pool) Invalidate

func (pool *Pool) Invalidate(bucketKey string)

Invalidate closes every idle state for bucketKey and drops the bucket. States checked out before the call stay checked out; they close or store on Return under the normal limit rules.

func (*Pool) InvalidateAll

func (pool *Pool) InvalidateAll()

InvalidateAll closes every idle state in every bucket.

func (*Pool) Length

func (pool *Pool) Length(bucketKey string) int

Length reports idle states stored for bucketKey.

func (*Pool) Return

func (pool *Pool) Return(bucketKey string, state *lua.LState)

Return stores state for bucketKey or closes it when the bucket is full. Nil states are ignored. Unknown pointers are closed, never stored, so a duplicate return cannot hand one state to two callers. Closed states are forgotten without a second close.

func (*Pool) SetBucketSize

func (pool *Pool) SetBucketSize(size int)

SetBucketSize replaces the per-bucket idle limit. Negative disables storage. Shrinking closes the newest excess idle states immediately.

Jump to

Keyboard shortcuts

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