softref

package
v1.122.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MPL-2.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPool = NewPool()

DefaultPool is a global default soft reference pool.

Functions

This section is empty.

Types

type Pool

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

Pool is used to track soft references to resources.

func NewPool

func NewPool() *Pool

NewPool creates a new soft reference pool.

func (*Pool) NewSoftRef

func (p *Pool) NewSoftRef(resource Resource) (ref *SoftRef, existedPreviously bool)

NewSoftRef returns a SoftRef to the given resource, along with a flag indicating if a reference existed previously.

type Resource

type Resource interface {
	// Key returns a unique key for this resource. Must never change.
	Key() string
	// Release is called when the resource is no longer being referenced by any remaining soft references.
	Release()
}

Resource is a resource that will be used with a pool.

type SoftRef

type SoftRef struct {
	Resource Resource
	Key      string
}

SoftRef is a soft reference to a given resource.

Jump to

Keyboard shortcuts

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