cyclebreaker

package
v0.4.87 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: ISC Imports: 12 Imported by: 0

Documentation

Overview

© 2020–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) ISC License

Index

Constants

View Source
const (
	Rfc3339s  = "2006-01-02 15:04:05Z07:00"
	Rfc3339ms = "2006-01-02 15:04:05.000Z07:00"
	Rfc3339us = "2006-01-02 15:04:05.000000Z07:00"
	Rfc3339ns = "2006-01-02 15:04:05.000000000Z07:00"
)

Variables

View Source
var ErrEndCallbacks = EndCallbacks(errors.New("end callbacks error"))

ErrEndCallbacks indicates upon retun from a callback function that no more callbacks are desired. It does not indicate an error and is not returned as an error by any other function than the callback.

callback invocations may be thread-safe, re-entrant and panic-handling but this depends on the callback-invoking implementation used.

Usage:

if errors.Is(err, parl.ErrEndCallbacks) { …
View Source
var ErrErrpNil = NilValueError(errors.New("errp cannot be nil"))

ErrErrpNil indicates that a function with an error pointer argument received an errp nil value.

if errors.Is(err, parl.ErrNilValue) …
View Source
var ErrNilValue = NilValueError(errors.New("end callbacks error"))

ErrNilValue indicates that a panic was caused by a value such as a function argument was nil that cannot be nil.

Usage:

if errors.Is(err, parl.ErrNilValue) { …

Functions

func AddToPanic

func AddToPanic(panicValue interface{}, additionalErr error) (err error)

AddToPanic takes a recover() value and adds it to additionalErr.

func Annotation

func Annotation() (annotation string)

Annotation provides a default annotation [base package].[function]: "mypackage.MyFunc"

func Close added in v0.4.58

func Close(closable io.Closer, errp *error)

Close is a deferrable function that closes an io.Closer object. Close handles panics. if errp is non-nil, panic values updates it using errors.AppendError.

func Closer added in v0.4.58

func Closer[T any](ch chan T, errp *error)

Closer is a deferrable function that closes a channel. Closer handles panics. if errp is non-nil, panic values updates it using errors.AppendError.

func CloserSend added in v0.4.58

func CloserSend[T any](ch chan<- T, errp *error)

CloserSend is a deferrable function that closes a send-channel. CloserSend handles panics. if errp is non-nil, panic values updates it using errors.AppendError.

func EndCallbacks

func EndCallbacks(err error) (err2 error)

func EnsureError

func EnsureError(panicValue interface{}) (err error)

AddToPanic ensures that a recover() value is an error or nil.

func HandleErrp

func HandleErrp(fn func(), errp *error)

HandleErrp recovers from a panic in fn storing at *errp. HandleErrp is deferable.

func HandlePanic

func HandlePanic(fn func()) (err error)

HandlePanic recovers from panic in fn returning error.

func HandleParlError

func HandleParlError(fn func(), storeError func(err error))

HandleParlError recovers from panic in fn invoking an error callback. HandleParlError is deferable storeError can be the thread-safe perrors.ParlError.AddErrorProc()

func Infallible added in v0.4.58

func Infallible(err error)

func Log

func Log(format string, a ...any)

func NilValueError

func NilValueError(err error) (err2 error)

func NoOnError

func NoOnError(err error)

NoOnError is used with Recover to silence the default error logging

func Recover

func Recover(annotation string, errp *error, onError func(error))

Recover recovers from a panic invoking a function no more than once. If there is *errp does not hold an error and there is no panic, onError is not invoked. Otherwise, onError is invoked exactly once. *errp is updated with a possible panic.

func Recover2

func Recover2(annotation string, errp *error, onError func(error))

Recover2 recovers from a panic and may invoke onError multiple times. onError is invoked if there is an error at *errp and on a possible panic. *errp is updated with a possible panic.

func RecoverInvocationPanic

func RecoverInvocationPanic(fn func(), errp *error)

RecoverInvocationPanic is intended to wrap callback invocations in the callee in order to recover from panics in the callback function. when an error occurs, perrors.AppendError appends the callback error to *errp. if fn is nil, a recovered panic results. if errp is nil, a panic is thrown, can be check with:

if errors.Is(err, parl.ErrNilValue) …

func Sprintf

func Sprintf(format string, a ...interface{}) string

Sprintf is a printer that supports comma in large numbers

Types

type AtomicBool

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

AtomicBool is a thread-safe flag. AtomicBool requires no initialization

var isDone parl.AtomicBool
if isDone.Set() // isDone was not set, but is set now
…
if !isDone.IsTrue() // isDone is not set

func (*AtomicBool) Clear

func (ab *AtomicBool) Clear() (wasSet bool)

Clear sets the flag to false and returns true if the flag was not already false. thread-safe

func (*AtomicBool) IsFalse

func (ab *AtomicBool) IsFalse() (isFalse bool)

IsFalse returns the flag’s current bool value. thread-safe

func (*AtomicBool) IsTrue

func (ab *AtomicBool) IsTrue() (isTrue bool)

IsTrue returns the flag’s current bool value. thread-safe

func (*AtomicBool) Set

func (ab *AtomicBool) Set() (wasNotSet bool)

Set sets the flag to true and returns true if the flag was not already true. thread-safe

type AtomicMax

type AtomicMax[T constraints.Integer] struct {
	// contains filtered or unexported fields
}

func NewAtomicMax

func NewAtomicMax[T constraints.Integer](value T) (atomicMax *AtomicMax[T])

func (*AtomicMax[T]) Max

func (max *AtomicMax[T]) Max() (value T, hasValue bool)

func (*AtomicMax[T]) Max1

func (max *AtomicMax[T]) Max1() (value T)

func (*AtomicMax[T]) Value

func (max *AtomicMax[T]) Value(value T) (isNewMax bool)

Jump to

Keyboard shortcuts

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