Documentation
¶
Index ¶
- Constants
- Variables
- type ContextConfig
- type ContextManager
- func (cm *ContextManager) Close() error
- func (cm *ContextManager) CloseContext(ctxType MemoryContextType, locked bool) error
- func (cm *ContextManager) GetOrCreateContext(ctxType MemoryContextType, config MemoryContextConfig) (*MemoryContext, bool, error)
- func (cm *ContextManager) ReturnContext(ctx *MemoryContext) error
- func (cm *ContextManager) StopCleanup()
- func (cm *ContextManager) ValidateContext(ctx *MemoryContext) bool
- type MemoryContext
- func (mm *MemoryContext) Acquire(objectType reflect.Type) any
- func (mc *MemoryContext) Close() error
- func (mc *MemoryContext) CreateChild() (*MemoryContext, error)
- func (mc *MemoryContext) CreatePool(objectType reflect.Type, config pool.PoolConfig, allocator func() any, ...) error
- func (mc *MemoryContext) GetChildren() []*MemoryContext
- func (mm *MemoryContext) GetPool(objectType reflect.Type) *pool.Pool[any]
- func (mc *MemoryContext) RegisterChild(child *MemoryContext)
- func (mm *MemoryContext) Release(objectType reflect.Type, obj any) bool
- type MemoryContextConfig
- type MemoryContextType
Constants ¶
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) 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) RegisterChild ¶
func (mc *MemoryContext) RegisterChild(child *MemoryContext)
Register a child with custom contex type, not the same as its parent
type MemoryContextConfig ¶
type MemoryContextConfig struct { Parent *MemoryContext ContextType MemoryContextType }
type MemoryContextType ¶
type MemoryContextType string
Click to show internal directories.
Click to hide internal directories.