softref

package
v1.80.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: MPL-2.0 Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultPool = NewPool(&jot.Logger{})

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(logger logadapter.WarnLogger) *Pool

NewPool creates a new soft reference pool. 'logger' may be nil.

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 {
	Key      string
	Resource Resource
}

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