concert

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: Apache-2.0 Imports: 3 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Canceled = context.Canceled

Canceled is the error returned when the signaler has been triggered.

Functions

func ClosedChan

func ClosedChan() <-chan struct{}

ClosedChan returns a closed read only channel.

Types

type OnceSignaler

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

OnceSignaler provides a channel that can only be closed once. In addition to the channel one can install callbacks to be executed if the signal is triggered. Once triggered all further close attempts will be ignored.

The zero value is not valid. NewOnceSignaler must be used to create an instance backed by a channel.

func NewOnceSignaler

func NewOnceSignaler() *OnceSignaler

NewOnceSignaler create a new OnceSignaler.

func (*OnceSignaler) Done

func (s *OnceSignaler) Done() <-chan struct{}

Done returns a channel one can listen on to check the the signaler has already been triggered.

func (*OnceSignaler) Err

func (s *OnceSignaler) Err() error

Err reports an Canceled event if the signaler has been triggered already

func (*OnceSignaler) OnSignal

func (s *OnceSignaler) OnSignal(fn func())

OnSignal installs a callback that will be executed if the signal is triggered. The callback will be called immediately if the signal has already been triggered.

func (*OnceSignaler) Trigger

func (s *OnceSignaler) Trigger()

Trigger triggers the signal, closing the channel returned by Done and calling all callbacks.

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