resource

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: GPL-3.0 Imports: 3 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckableResource

type CheckableResource interface {
	Resource
	IsUsable() bool
}

type Container

type Container[T Resource] interface {
	io.Closer
	GetOpen(key string, open func() (T, error)) (T, error)
	CloseUnused(isUsed func(key string) bool) error
}

type Resource

type Resource = io.Closer

type Singleton

type Singleton[T Resource] struct {
	// contains filtered or unexported fields
}

Singleton represents a set of resources identified by an unique key.

func NewSingleton

func NewSingleton[T Resource](log *log.Logger) *Singleton[T]

func (*Singleton[T]) Close

func (s *Singleton[T]) Close() error

func (*Singleton[T]) CloseUnused

func (s *Singleton[T]) CloseUnused(isUsed func(key string) bool) error

func (*Singleton[T]) GetOpen

func (s *Singleton[T]) GetOpen(key string, open func() (T, error)) (T, error)

type Tracker

type Tracker[T Resource] struct {
	C Container[T]
	// contains filtered or unexported fields
}

Tracker is a container wrapper that tracks whether resources were used since last MarkAllUnused call.

func NewTracker

func NewTracker[T Resource](c Container[T]) *Tracker[T]

func (*Tracker[T]) Close

func (t *Tracker[T]) Close() error

func (*Tracker[T]) CloseUnused

func (t *Tracker[T]) CloseUnused(isUsed func(key string) bool) error

func (*Tracker[T]) GetOpen

func (t *Tracker[T]) GetOpen(key string, open func() (T, error)) (T, error)

func (*Tracker[T]) MarkAllUnused

func (t *Tracker[T]) MarkAllUnused()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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