instance

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package instance manages configured resources independently of processes and connections. Consumers supply a key including tenant/subject scope as needed.

Index

Constants

This section is empty.

Variables

View Source
var ErrCapacity = errors.New("plugin instance capacity reached")
View Source
var ErrUpdating = errors.New("plugin instance update in progress")

Functions

This section is empty.

Types

type Event

type Event struct {
	Key      string
	Revision string
	State    string
}

Event reports lifecycle metadata without configuration values.

type Factory

type Factory[T any] func(context.Context, string, json.RawMessage) (T, func() error, error)

type Lease

type Lease[T any] struct {
	Value    T
	Revision string
	// contains filtered or unexported fields
}

func (*Lease[T]) Release

func (l *Lease[T]) Release() error

type Manager

type Manager[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](opts Options[T]) (*Manager[T], error)

func (*Manager[T]) Acquire

func (m *Manager[T]) Acquire(key string) (*Lease[T], error)

func (*Manager[T]) Close

func (m *Manager[T]) Close(ctx context.Context) error

Close stops admission and waits for leases/factories/disposals. A deadline leaves the manager closed; callers can wait again. Resources are never destroyed while leased. Cleanup callbacks must be bounded by their owner.

func (*Manager[T]) Configure

func (m *Manager[T]) Configure(ctx context.Context, key, revision string, config json.RawMessage) error

Configure atomically replaces an instance only after successful validation and creation. Revision must change with configuration. Existing leases keep the old instance alive until released. Factories must honor ctx; callbacks are called outside the manager lock. Capacity includes retiring instances.

func (*Manager[T]) Remove

func (m *Manager[T]) Remove(key string) error

type Options

type Options[T any] struct {
	// Observe must be fast and safe for concurrent calls.
	Observe  func(Event)
	Capacity int
	Validate func(json.RawMessage) error
	Create   Factory[T]
}

Jump to

Keyboard shortcuts

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