Help us shape the future of Go! Take the 2026 Go Developer Survey

refcount

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessRefCount

func AccessRefCount[T comparable](
	ctx context.Context,
	rc *RefCount[T],
	cb func(T) error,
) error

AccessRefCount adds a reference to the RefCount while the fn executes.

func WaitRefCount

func WaitRefCount[T comparable](
	ctx context.Context,
	target *ccontainer.CContainer[T],
	targetErr *ccontainer.CContainer[*error],
) (T, error)

WaitRefCount waits for a RefCount container handling errors. targetErr can be nil

Types

type Ref

type Ref[T comparable] struct {
	// contains filtered or unexported fields
}

Ref is a reference to a RefCount.

func (*Ref[T]) Release

func (k *Ref[T]) Release()

Release releases the reference.

type RefCount

type RefCount[T comparable] struct {
	// contains filtered or unexported fields
}

RefCount is a refcount driven object container. Wraps a ccontainer with a ref count mechanism. When there are no references, the container contents are released.

func NewRefCount

func NewRefCount[T comparable](
	ctx context.Context,
	target *ccontainer.CContainer[T],
	targetErr *ccontainer.CContainer[*error],
	resolver func(ctx context.Context) (T, func(), error),
) *RefCount[T]

NewRefCount builds a new RefCount. ctx, target and targetErr can be empty

func (*RefCount[T]) AddRef

func (r *RefCount[T]) AddRef(cb func(val T, err error)) *Ref[T]

AddRef adds a reference to the RefCount container. cb is an optional callback to call when the value changes.

func (*RefCount[T]) SetContext added in v0.18.1

func (r *RefCount[T]) SetContext(ctx context.Context)

SetContext updates the context to use for the RefCount container resolution. If ctx=nil the RefCount will wait until ctx != nil to start. This also restarts resolution, if there are any refs.

Jump to

Keyboard shortcuts

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