contexts

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxReferences   = 10
	DefaultMaxIdleTime     = 5 * time.Minute
	DefaultCleanupInterval = 1 * time.Minute
	MinMaxReferences       = 1
	MinMaxIdleTime         = 1 * time.Second
	MinCleanupInterval     = 1 * time.Second
)

Variables

View Source
var (
	ErrContextNotFound      = errors.New("context not found")
	ErrContextInUse         = errors.New("context is currently in use")
	ErrInvalidContextType   = errors.New("invalid context type")
	ErrContextClosed        = errors.New("context is closed")
	ErrContextManagerClosed = errors.New("context manager is closed")
	ErrMaxReferencesReached = errors.New("maximum references reached")
	ErrInvalidConfig        = errors.New("invalid configuration")
)

Functions

This section is empty.

Types

type ContextConfig

type ContextConfig struct {
	// how many goroutines can use the context at the same time.
	MaxReferences int32

	// how long the context can be idle before it is automatically cleaned up.
	MaxIdleTime time.Duration

	// the interval at which the context will be cleaned up when it is not in use.
	CleanupInterval time.Duration
}

type ContextManager

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

func NewContextManager

func NewContextManager(config *ContextConfig) *ContextManager

NewContextManager creates a new context manager with default configuration

func (*ContextManager) Close

func (cm *ContextManager) Close() error

Close stops the cleanup routine and closes all managed contexts

func (*ContextManager) CloseContext

func (cm *ContextManager) CloseContext(ctxType MemoryContextType, locked bool) error

CloseContext closes a context and removes it from the manager

func (*ContextManager) GetOrCreateContext

func (cm *ContextManager) GetOrCreateContext(ctxType MemoryContextType, config MemoryContextConfig) (*MemoryContext, bool, error)

getOrCreateContext is the internal version of GetOrCreateContext

func (*ContextManager) ReturnContext

func (cm *ContextManager) ReturnContext(ctx *MemoryContext) error

ReturnContext returns a context to the manager and updates its state

func (*ContextManager) StopCleanup

func (cm *ContextManager) StopCleanup()

StopCleanup stops the auto-cleanup routine

func (*ContextManager) ValidateContext

func (cm *ContextManager) ValidateContext(ctx *MemoryContext) bool

ValidateContext checks if a context is valid and active

type MemoryContext

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

func NewMemoryContext

func NewMemoryContext(config MemoryContextConfig) *MemoryContext

func (*MemoryContext) Acquire

func (mm *MemoryContext) Acquire(objectType reflect.Type) any

func (*MemoryContext) Close

func (mc *MemoryContext) Close() error

func (*MemoryContext) CreateChild

func (mc *MemoryContext) CreateChild() (*MemoryContext, error)

Creates and registers a child context with the same context type as the parent.

func (*MemoryContext) CreatePool

func (mc *MemoryContext) CreatePool(objectType reflect.Type, config pool.PoolConfig, allocator func() any, cleaner func(any)) error

Object Methods checking github username update

func (*MemoryContext) GetChildren

func (mc *MemoryContext) GetChildren() []*MemoryContext

getter for the children

func (*MemoryContext) GetPool

func (mm *MemoryContext) GetPool(objectType reflect.Type) *pool.Pool[any]

func (*MemoryContext) RegisterChild

func (mc *MemoryContext) RegisterChild(child *MemoryContext)

Register a child with custom contex type, not the same as its parent

func (*MemoryContext) Release

func (mm *MemoryContext) Release(objectType reflect.Type, obj any) bool

type MemoryContextConfig

type MemoryContextConfig struct {
	Parent      *MemoryContext
	ContextType MemoryContextType
}

type MemoryContextType

type MemoryContextType string

Jump to

Keyboard shortcuts

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