parl

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: ISC Imports: 13 Imported by: 14

README

Parl


A Go library for parallel programming of command-line utilities and system services

features: moderator, sqlite interface, package-selectable logging, debouncer, self-signed certificate authority, watchers, thread management, file system scan and operations, …


© 2022–present Harald Rudell (https://haraldrudell.github.io/haraldrudell/)
ISC License

“justice, peace and massive virtual parallelism”

How to use

import "github.com/haraldrudell/parl"

Documentation

Go Reference  Documentation in the Go Package Index

On 3/16/2022 Parl was open-sourced under an ISC License
Parl is about 9,000 lines of Go code with first line written on November 21, 2018

© 2022–present Harald Rudell harald.rudell@gmail.com (https://haraldrudell.github.io/haraldrudell/)

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

View Source
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"
)
View Source
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

View Source
var ErrModeratorShutdown = errors.New("Moderator shut down")

Functions

func AddToPanic

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

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 Errorf

func Errorf(format string, a ...interface{}) (err error)

func HandleErrp added in v0.2.2

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

HandleErrp recovers from panics when executing fn. A panic is stored at errp using error116.AppendError()

func HandlePanic

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

HandlePanic recovers from panics when executing fn. A panic is returned in err

func HandleParlError added in v0.2.2

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

HandleErrp recovers from panics when executing fn. A panic is provided to the storeError function. storeError can be the thread-safe error116.ParlError.AddErrorProc()

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 IsSilent

func IsSilent() (isSilent bool)

IsSilent if true it means that Info does not print

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 New

func New(s string) error

func NewDebouncer

func NewDebouncer(d time.Duration, receiver ReceiverFunc, sender SenderFunc, ctx context.Context) (err error)

Debouncer debounces event streams of Value

func Out

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

Out prints extected output to stdout

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 SetDebug

func SetDebug(debug bool)

if SetDebug is true, all Debug prints everywhere produce output. More selective debug printing can be achieved using SetInfoRegexp that matches package names.

func SetRegexp

func SetRegexp(regExp string) (err error)

func SetSilent

func SetSilent(silent bool)

SetSilent

func Sprintf added in v0.2.0

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

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 NewFanOut

func NewFanOut() (fo *FanOut)

func (*FanOut) Do

func (cr *FanOut) Do(name string, proc FanProc)

Do executes a procedure in a goroutine that has no result other than a possible non-nil error

func (*FanOut) Run

func (cr *FanOut) Run(name string, thunk FanThunk)

Run executes a thunk in a goroutine with a possible non-nil result and a possible non-nil error

func (*FanOut) Wait

func (cr *FanOut) Wait()

Wait waits for all Do and Run invocations to complete, then shuts down

type FanProc

type FanProc func() (err error)

type FanThunk

type FanThunk func() (result interface{}, err error)

type Moderator

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

Moderator invokes functions at a limited level of parallelism

func NewModerator

func NewModerator(parallelism uint64) (mo *Moderator)

NewModerator creates a new Moderator used to limit parallelism

func (*Moderator) Do

func (mo *Moderator) Do(fn func() error) (err error)

Do calls fn limited by the moderator’s parallelism. If the moderator is shut down, ErrModeratorShutdown is returned

func (*Moderator) Shutdown

func (mo *Moderator) Shutdown()

func (*Moderator) Status

func (mo *Moderator) Status() (parallelism uint64, available uint64, waiting uint64, isShutdown bool)

func (*Moderator) String

func (mo *Moderator) String() (s string)

type Password

type Password interface {
	HasPassword() (hasPassword bool)
	Password() (password string)
}

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

func (*SerialDo) Do

func (sdo *SerialDo) Do(now time.Time) (nowPending bool)

Invoke thunk serially, maximum queue one invocation, drop additional invocation requests prior to idle. non-blocking Thread-safe

func (*SerialDo) Shutdown

func (sdo *SerialDo) Shutdown()

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

func NewTimer

func NewTimer(label string) (t *Timer)

NewTimer gets a simple timer with duration or string output

func (*Timer) End

func (t *Timer) End() (d time.Duration)

End gets duration

func (*Timer) Endms

func (t *Timer) Endms() (ms string)

Endms gets tring with duration in ms

type TriggeringChan

type TriggeringChan uint8
const (
	TimerCh TriggeringChan = iota
	DoneCh
	ValueCh
)

type Value

type Value interface{}

Value is an event value that is being debounced

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 implementing a service or command-line utility
Package mains contains functions for implementing a service or 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 parlp provides portable computer process information
Package parlp provides portable computer process information
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 runt provides an interface to the Go standard library’s runtime package using only serializable simple types
Package runt provides an interface to the Go standard library’s runtime package using only serializable simple types
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

Jump to

Keyboard shortcuts

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