proc

package
v1.2.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2015 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package proc provides opinionated utilities for processing background operations and future errors, somewhat inspired by libprocess.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorChan

func ErrorChan(err error) <-chan error

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

func ErrorChanf(msg string, args ...interface{}) <-chan error

ErrorChanf is a convenience func that returns a chan that yields an error generated from the given msg format and args.

func IsIllegalState

func IsIllegalState(err error) bool

func IsProcessTerminated

func IsProcessTerminated(err error) bool

func OnError

func OnError(ch <-chan error, f func(error), abort <-chan struct{}) <-chan struct{}

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 Action

type Action func()

Action is something that executes in the context of a process

type Config

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

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 DoerFunc

type DoerFunc func(Action) <-chan error

DoerFunc is an adapter func for Doer interface

func (DoerFunc) Do

func (f DoerFunc) Do(a Action) <-chan error

invoke the f on action a. returns an illegal state error if f is nil.

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{}
}

func DoWith

func DoWith(other Process, d Doer) Process

DoWith returns a process that, within its execution context, delegates to the specified Doer. Expect a panic if either the given Process or Doer are nil.

func New

func New() Process

Jump to

Keyboard shortcuts

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