Documentation ¶
Overview ¶
Package parl handles inter-thread communication and controls parallelism
Logging of extected output is via Out(string, ...interface{}). Parl logging uses comma separator for numbers and is thread safe
Log(string, ...interface{}) always outputs to stderr. Console is the same intended to be used for command-line interactivity. SetDebug(true) appends code location
Info is active by default and outputs to stderr. SetSilent(true) removes this output. SetDebug(true) appends code location IsSilent deteremines if Info printing applies
Debug only prints if SetDebug(true) or the code location matches SetInfoRegexp(). The string matched for regular expression looks like: “github.com/haraldrudell/parl.FuncName” IsThisDebug determines if debug is active for the executing function
parl.D is intended for temporary printouts to be removed before check-in
parl provides generic recovery for goroutines and functions: capturing panics, annotating and storing errors and invoking an error handling function on errors:
func f() (err error) { defer parl.Recover(parl.Annotation(), &err, onError func(e error) { … }) …
Default error string: “Recover from panic in somePackage.someFunction: 'File not found'. For multiple errors, Recover uses error116 error lists, while Recover2 instead invokes onError multiple times
Parl is about 9,000 lines of Go code with first line written on November 21, 2018 ¶
On 3/16/2022 Parl was open-sourced under an ISC License
© 2020–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
Index ¶
- Constants
- Variables
- func AddToPanic(panicValue interface{}, additionalErr error) (err error)
- func Annotation() (annotation string)
- func Console(format string, a ...interface{})
- func D(format string, a ...interface{})
- func Debug(format string, a ...interface{})
- func EnsureError(panicValue interface{}) (err error)
- func Errorf(format string, a ...interface{}) (err error)
- func HandlePanic(fn func()) (err error)
- func Info(format string, a ...interface{})
- func IsSilent() (isSilent bool)
- func IsThisDebug() bool
- func Log(format string, a ...interface{})
- func New(s string) error
- func NewDebouncer(d time.Duration, receiver ReceiverFunc, sender SenderFunc, ctx context.Context) (err error)
- func Out(format string, a ...interface{})
- func Recover(annotation string, errp *error, onError func(error))
- func Recover2(annotation string, errp *error, onError func(error))
- func SetDebug(debug bool)
- func SetRegexp(regExp string) (err error)
- func SetSilent(silent bool)
- func Sprintf(format string, a ...interface{}) string
- type AtomicBool
- type FSLocation
- type FanOut
- type FanProc
- type FanThunk
- type Moderator
- type Password
- type ReceiverFunc
- type SenderFunc
- type SerialDo
- type SerialDoEvent
- type SerialDoFunc
- type Timer
- type TriggeringChan
- type Value
Constants ¶
const ( Rfc3339s = "2006-01-02 15:04:05-07:00" Rfc3339ms = "2006-01-02 15:04:05.999-07:00" Rfc3339us = "2006-01-02 15:04:05.999999-07:00" Rfc3339ns = "2006-01-02 15:04:05.999999999-07:00" Rfc3339sz = "2006-01-02T15:04:05Z" Rfc3339msz = "2006-01-02T15:04:05.999Z" Rfc3339usz = "2006-01-02T15:04:05.999999Z" Rfc3339nsz = "2006-01-02T15:04:05.999999999Z" )
const ( SerialDoReady = 0 + iota SerialDoLaunch // from idle, now time SerialDoPending // queued up invocation, request time SerialDoPendingLaunch // launch of pending invocation, request time SerialDoIdle // busy since )
Variables ¶
var ErrModeratorShutdown = errors.New("Moderator shut down")
Functions ¶
func AddToPanic ¶
func Annotation ¶
func Annotation() (annotation string)
func Console ¶
func Console(format string, a ...interface{})
Console always print intended for command-line interactivity if debug is enabled, code location is appended
func D ¶
func D(format string, a ...interface{})
D prints to stderr with code location Thread safe. D is meant for temporary output intended to be removed before check-in
func Debug ¶
func Debug(format string, a ...interface{})
Debug outputs only if debug is configured or the code location package matches regexp
func EnsureError ¶
func EnsureError(panicValue interface{}) (err error)
func HandlePanic ¶
func HandlePanic(fn func()) (err error)
HandlePanic executes a function wrapped in panic recovery. If the function panics, HandlePanic returns an error value
func Info ¶
func Info(format string, a ...interface{})
Info prints unless silence has been configured with SetSilence(true) IsSilent deteremines the state of silence if debug is enabled, code location is appended
func IsThisDebug ¶
func IsThisDebug() bool
IsThisDebug returns whether debug logging is configured for the executing function
func Log ¶
func Log(format string, a ...interface{})
Log invocations always print if debug is enabled, code location is appended
func NewDebouncer ¶
func NewDebouncer(d time.Duration, receiver ReceiverFunc, sender SenderFunc, ctx context.Context) (err error)
Debouncer debounces event streams of Value
func Recover ¶
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 ¶
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.
Types ¶
type AtomicBool ¶
type AtomicBool struct {
// contains filtered or unexported fields
}
func (*AtomicBool) Clear ¶
func (ab *AtomicBool) Clear() (wasSet bool)
func (*AtomicBool) IsTrue ¶
func (ab *AtomicBool) IsTrue() (isTrue bool)
func (*AtomicBool) Set ¶
func (ab *AtomicBool) Set() (wasNotSet bool)
type FSLocation ¶
type FSLocation interface {
Directory() (directory string)
}
type FanOut ¶
type FanOut struct { ErrCh chan error Results chan interface{} // contains filtered or unexported fields }
func (*FanOut) Do ¶
Do executes a procedure in a goroutine that has no result other than a possible non-nil error
type Moderator ¶
type Moderator struct {
// contains filtered or unexported fields
}
Moderator invokes functions at a limited level of parallelism
func NewModerator ¶
NewModerator creates a new Moderator used to limit parallelism
func (*Moderator) Do ¶
Do calls fn limited by the moderator’s parallelism. If the moderator is shut down, ErrModeratorShutdown is returned
type ReceiverFunc ¶
type ReceiverFunc func(c <-chan time.Time, done <-chan struct{}) (which TriggeringChan, value Value)
ReceiverFunc takes two channels, listens to them and a typed channel, returns what channel triggered and a possible untyped value
type SenderFunc ¶
type SenderFunc func([]Value)
SenderFunc takes an untyped value, type asserts and sends on a typed channel
type SerialDo ¶
type SerialDo struct { ErrCh chan error ID string Wg sync.WaitGroup // contains filtered or unexported fields }
serialdo invokes method in sequence
func NewSerialDo ¶
func NewSerialDo(thunk func(), eventReceiver SerialDoFunc, ctx context.Context) (sdo *SerialDo)
NewSerialDo SerialDo. errors on sdo.ErrCh
type SerialDoEvent ¶
type SerialDoEvent uint8
type SerialDoFunc ¶
type SerialDoFunc func(SerialDoEvent, *SerialDo, *time.Time)
type Timer ¶
type Timer struct { Label string // contains filtered or unexported fields }
Timer is a simple request timer
type TriggeringChan ¶
type TriggeringChan uint8
const ( TimerCh TriggeringChan = iota DoneCh ValueCh )
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
parl
parl.go demonstrate usage of the parl package, a go library for command-line utilities and concurrency
|
parl.go demonstrate usage of the parl package, a go library for command-line utilities and concurrency |
Package error116 enrichens error values with string data, stack traces, associated errors, less severe warnings, thread-safe containers and comprehensive error string representations.
|
Package error116 enrichens error values with string data, stack traces, associated errors, less severe warnings, thread-safe containers and comprehensive error string representations. |
Package errorglue contains helful declarations that are not important
|
Package errorglue contains helful declarations that are not important |
Package ev provides standardized goroutine management events contain thread completions, failures and any type of data items.
|
Package ev provides standardized goroutine management events contain thread completions, failures and any type of data items. |
Package evx contains declarations not essential to event handling
|
Package evx contains declarations not essential to event handling |
Package mains contains functions for executing a command-line utility
|
Package mains contains functions for executing a command-line utility |
omaps
module
|
|
Package parlca provides a self-signed certificate authority
|
Package parlca provides a self-signed certificate authority |
Package parlfs provides file-system related functions Package parlfs provides file-system related functions © 2020–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
|
Package parlfs provides file-system related functions Package parlfs provides file-system related functions © 2020–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) |
Package parlnet provides IP-related functions with few dependencies beyond the net package
|
Package parlnet provides IP-related functions with few dependencies beyond the net package |
Package parlos provides simplified functions related to the os package
|
Package parlos provides simplified functions related to the os package |
Package parltime provides time utility functions
|
Package parltime provides time utility functions |
pfs
module
|
|
process
module
|
|
Package progress provides printable progress reporting for multi-threaded operations
|
Package progress provides printable progress reporting for multi-threaded operations |
psql
module
|
|
pterm
module
|
|
Package sqldb interfaces database/sql
|
Package sqldb interfaces database/sql |
Package sqlite wraps modernc.org/sqlite
|
Package sqlite wraps modernc.org/sqlite |
sqliter
module
|
|
watchfs
module
|
|
yaml
module
|
|
yamler
module
|