Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Canceled = context.Canceled
Canceled is the error returned when the signaler has been triggered.
Functions ¶
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) Fail ¶
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.
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. |