concert

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2021 License: Apache-2.0 Imports: 2 Imported by: 9

README

Build Status

go-concert

go-concert a is a library of synchronization patterns when dealing with go-routines

License

Apache 2.0.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RefCount

type RefCount struct {
	Action  func(err error)
	OnError func(old, new error) error
	// contains filtered or unexported fields
}

RefCount is an atomic reference counter. It can be used to track a shared resource it's lifetime and execute an action once it is clear the resource is not needed anymore.

The zero value of RefCount is already in a valid state, which can be Released already.

func (*RefCount) Err

func (c *RefCount) Err() error

Err returns the current error stored by the reference counter.

func (*RefCount) Fail

func (c *RefCount) Fail(err error) bool

Fail adds an error to the reference counter. OnError will be called if configured, so to compute the actual error. If OnError is not configured, the first error reported will be stored by the reference counter only.

Fail releases the reference counter.

func (*RefCount) Release

func (c *RefCount) Release() bool

Release decreases the reference count. It returns true, if the reference count has reached a 'free' state. Releasing a reference count in a free state will trigger a panic. If an Action is configured, then this action will be run once the refcount becomes free.

func (*RefCount) Retain

func (c *RefCount) Retain()

Retain increases the ref count.

Directories

Path Synopsis
Package atomic provides common primitive types with atomic accessors.
Package atomic provides common primitive types with atomic accessors.
Package ctxtool provides extra functionality and tools for use with context.Context.
Package ctxtool provides extra functionality and tools for use with context.Context.

Jump to

Keyboard shortcuts

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