idmanager

package
v1.3.106 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package idmanager pkg/app/idmanager/delta_informer.go c2-vis-appsvc

Package idmanager pkg/app/idmanager/manager.go c2-vis-appsvc

Package idmanager pkg/app/idmanager/util.go c2-vis-appsvc

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMoreAvailableValues is returned when all the slots are reserved.
	ErrNoMoreAvailableValues = errors.New("no more available values")

	// ErrValueAlreadyExists is returned when value associated with the specified key already exists.
	ErrValueAlreadyExists = errors.New("value already exists")

	// ErrManagerClosed is returned by Set / ReserveNextID once CloseAll has run.
	// The caller owns the value it was about to store, so it must close it.
	ErrManagerClosed = errors.New("id manager is closed")
)

Functions

func AssertConn

func AssertConn(v any) (net.Conn, error)

AssertConn asserts that `v` is of type `net.Conn`.

func AssertListener

func AssertListener(v any) (net.Listener, error)

AssertListener asserts that `v` is of type `net.Listener`.

Types

type DeltaInformer

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

DeltaInformer informs when there has been a change to the id-manager. .Trigger() and .Stop() can not be called concurrently to each other.

func NewDeltaInformer

func NewDeltaInformer() *DeltaInformer

NewDeltaInformer creates a new DeltaInformer.

func (*DeltaInformer) Chan

func (di *DeltaInformer) Chan() <-chan int

Chan returns the internal chan that gets triggered when a change occurs.

func (*DeltaInformer) Stop

func (di *DeltaInformer) Stop()

Stop closes the internal chan.

func (*DeltaInformer) Trigger

func (di *DeltaInformer) Trigger(n int)

Trigger should be called whenever the internal chan should be triggered.

type Manager

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

Manager manages allows to store and retrieve arbitrary values associated with the `uint16` key in a thread-safe manner. Provides method to generate key.

func New

func New() *Manager

New constructs new `Manager`.

func (*Manager) Add

func (m *Manager) Add(id uint16, v any) (free func() bool, err error)

Add adds the new value `v` associated with `id`.

func (*Manager) AddDeltaInformer

func (m *Manager) AddDeltaInformer() *DeltaInformer

AddDeltaInformer adds a DeltaInformer to the id manager and returns the DeltaInformer.

func (*Manager) CloseAll

func (m *Manager) CloseAll()

CloseAll closes and removes all internal values that implements io.Closer

func (*Manager) DoRange

func (m *Manager) DoRange(next func(id uint16, v any) bool)

DoRange performs range over the manager contents. Loop stops when `next` returns false.

func (*Manager) Get

func (m *Manager) Get(id uint16) (any, bool)

Get gets the value associated with the `id`.

func (*Manager) Len

func (m *Manager) Len() int

Len returns the combined count of both reserved and used IDs.

func (*Manager) Pop

func (m *Manager) Pop(id uint16) (any, error)

Pop removes value specified by `id` from the idManager instance and returns it.

func (*Manager) ReserveNextID

func (m *Manager) ReserveNextID() (id *uint16, free func() bool, err error)

ReserveNextID reserves next free slot for the value and returns the id for it.

func (*Manager) Set

func (m *Manager) Set(id uint16, v any) error

Set sets value `v` associated with `id`.

Jump to

Keyboard shortcuts

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