local

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientIdentifierStringMapper

type ClientIdentifierStringMapper[ClientIdentifier any] func(ctx context.Context, clientIdentifier ClientIdentifier) (string, error)

ClientIdentifierStringMapper is a function type that can be used to create a string representation of a client identifier.

type EventHandler added in v0.2.0

type EventHandler[ClientIdentifier any] interface {
	event.Handler[ClientIdentifier]
}

EventHandler defines a set of event handlers that can be invoked when certain events occur within an instance of [Registrat].

type NopEventHandler added in v0.2.0

type NopEventHandler[ClientIdentifier any] struct {
	*event.NopHandler[ClientIdentifier]
}

NopEventHandler is a no-op implementation of EventHandler.

func NewNopEventHandler added in v0.2.0

func NewNopEventHandler[ClientIdentifier any]() *NopEventHandler[ClientIdentifier]

NewNopEventHandler creates a new instance of NopEventHandler.

type Registrar

type Registrar[ClientIdentifier any] struct {
	// contains filtered or unexported fields
}

Registrar provides a locally-managed instance of a Registrar. All state is managed in memory, and all resource close handlers are executed in the same process. This is not intended for any distributed resource management.

func NewRegistrar

func NewRegistrar[ClientIdentifier any](
	ctx context.Context,
	clientIdentifierStringMapper ClientIdentifierStringMapper[ClientIdentifier],
	maximumPerClientConcurrency int,
	resourceCleanupFrequency time.Duration,
	resourceExpiry time.Duration,
	eventHandler EventHandler[ClientIdentifier],
	gauge metrics.Gauge[ClientIdentifier],
) (*Registrar[ClientIdentifier], error)

NewRegistrar creates a new instance of a Registrar with the provided configuration. Constructors of this registrar are responsible for calling Close at time of application shutdown. clientIdentifierStringMapper is used to map client identifiers to strings for internal management. This allows the Registrar to support any type of client identifier, as long as it can be mapped to a string. maximumPerClientConcurrency is the maximum number of concurrent resources allowed per client. If a client exceeds this limit, the Registrar will automatically close resources until the limit is no longer exceeded. resourceCleanupFrequency is how often the Registrar will check for and clean up abandoned resources. Abandoned resources are those that have exceeded the resourceExpiry duration without being either forcibly closed or having unregistered themselves. resourceExpiry is the duration after which a resource is considered abandoned if it has not been closed or unregistered.

func (*Registrar[ClientIdentifier]) Close

func (r *Registrar[ClientIdentifier]) Close() error

Close cleans up any resources used by the registrar.

func (*Registrar[ClientIdentifier]) RegisterResourceOpen

func (r *Registrar[ClientIdentifier]) RegisterResourceOpen(ctx context.Context, clientIdentifier ClientIdentifier, resourceCloseHandler registration.ResourceCloseHandler) (registration.ResourceOpenDeregistration, error)

Jump to

Keyboard shortcuts

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