refcount

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 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. 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.

Jump to

Keyboard shortcuts

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