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
- func Acquire(bucketKey string, createState func() *lua.LState) *lua.LState
- func BucketSize() int
- func Invalidate(bucketKey string)
- func InvalidateAll()
- func Length(bucketKey string) int
- func Return(bucketKey string, state *lua.LState)
- func SetBucketSize(size int)
- type Pool
- func (pool *Pool) Acquire(bucketKey string, createState func() *lua.LState) *lua.LState
- func (pool *Pool) BucketSize() int
- func (pool *Pool) Invalidate(bucketKey string)
- func (pool *Pool) InvalidateAll()
- func (pool *Pool) Length(bucketKey string) int
- func (pool *Pool) Return(bucketKey string, state *lua.LState)
- func (pool *Pool) SetBucketSize(size int)
Constants ¶
const DefaultBucketSize = 16
DefaultBucketSize caps idle states stored per bucket.
Variables ¶
This section is empty.
Functions ¶
func Acquire ¶
Acquire pops an idle state for bucketKey from the shared pool or builds one with createState.
func Invalidate ¶
func Invalidate(bucketKey string)
Invalidate closes every idle state for bucketKey in the shared pool.
func Return ¶
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 ¶
NewPool builds an empty pool holding at most maximumPerBucket idle states per bucket. Negative values disable storage.
func (*Pool) Acquire ¶
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 ¶
BucketSize reports the per-bucket idle limit.
func (*Pool) Invalidate ¶
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) Return ¶
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 ¶
SetBucketSize replaces the per-bucket idle limit. Negative disables storage. Shrinking closes the newest excess idle states immediately.