Documentation ¶
Overview ¶
Package proc provides opinionated utilities for processing background operations and future errors, somewhat inspired by libprocess.
Index ¶
- func ErrorChan(err error) <-chan error
- func ErrorChanf(msg string, args ...interface{}) <-chan error
- func IsIllegalState(err error) bool
- func IsProcessTerminated(err error) bool
- func OnError(ch <-chan error, f func(error), abort <-chan struct{}) <-chan struct{}
- type Action
- type Config
- type Context
- type Doer
- type DoerFunc
- type ErrorOnce
- type Process
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorChan ¶
ErrorChan is a convenience func that returns a chan that yields the given error. If err is nil then a closed chan is returned.
func ErrorChanf ¶
ErrorChanf is a convenience func that returns a chan that yields an error generated from the given msg format and args.
func IsIllegalState ¶
func IsProcessTerminated ¶
func OnError ¶
OnError spawns a goroutine that waits for an error. if a non-nil error is read from the channel then the handler func is invoked, otherwise (nil error or closed chan) the handler is skipped. if a nil handler is specified then it's not invoked. the signal chan that's returned closes once the error process logic (and handler, if any) has completed.
Types ¶
type Context ¶
type Context interface { // end (terminate) the execution context End() <-chan struct{} // return a signal chan that will close upon the termination of this process Done() <-chan struct{} }
type Doer ¶
type Doer interface { // execute some action in some context. actions are to be executed in a // concurrency-safe manner: no two actions should execute at the same time. // errors are generated if the action cannot be executed (not by the execution // of the action) and should be testable with the error API of this package, // for example, IsProcessTerminated. Do(Action) <-chan error }
type ErrorOnce ¶
type ErrorOnce interface { // Err returns a chan that only ever sends one error, either obtained via Report() or Forward(). Err() <-chan error // Report reports the given error via Err(), but only if no other errors have been reported or forwarded. Report(error) // Report reports an error via Err(), but only if no other errors have been reported or forwarded, using // fmt.Errorf to generate the error. Reportf(string, ...interface{}) // Send is non-blocking; it spins up a goroutine that reports an error (if any) that occurs on the error chan. Send(<-chan error) ErrorOnce // WaitFor returns true if an error is received within the specified duration, otherwise false WaitFor(time.Duration) (error, bool) // contains filtered or unexported methods }
ErrorOnce an error promise. If we ever start building out support for other promise types it will probably make sense to group them in some sort of "promises" package.
func NewErrorOnce ¶
func NewErrorOnce(abort <-chan struct{}) ErrorOnce
NewErrorOnce creates an ErrorOnce that aborts blocking func calls once the given abort chan has closed.
type Process ¶
type Process interface { Context Doer // see top level OnError func. this implementation will terminate upon the arrival of // an error (and subsequently invoke the error handler, if given) or else the termination // of the process (testable via IsProcessTerminated). OnError(<-chan error, func(error)) <-chan struct{} // return a signal chan that will close once the process is ready to run actions Running() <-chan struct{} }