Documentation
¶
Index ¶
- type Future
- func (f Future[T]) If(cond bool) Future[T]
- func (f Future[T]) Ignore() func()
- func (f Future[T]) Join(merge func(T, T) T, ops ...Future[T]) Future[T]
- func (f Future[T]) Limit(in int) Future[T]
- func (f Future[T]) Lock() Future[T]
- func (f Future[T]) Not(cond bool) Future[T]
- func (f Future[T]) Once() Future[T]
- func (f Future[T]) PostHook(fn func()) Future[T]
- func (f Future[T]) PreHook(fn func()) Future[T]
- func (f Future[T]) RecoverPanic() (T, error)
- func (f Future[T]) Reduce(merge func(T, T) T, next Future[T]) Future[T]
- func (f Future[T]) Resolve() T
- func (f Future[T]) Safe() func() (T, error)
- func (f Future[T]) Slice() func() []T
- func (f Future[T]) TTL(dur time.Duration) Future[T]
- func (f Future[T]) When(c func() bool) Future[T]
- func (f Future[T]) WithLock(m *sync.Mutex) Future[T]
- func (f Future[T]) WithLocker(m sync.Locker) Future[T]
- type Handler
- func (of Handler[T]) All(in ...T)
- func (of Handler[T]) Capture(in T) func()
- func (of Handler[T]) Chain(chain ...Handler[T]) Handler[T]
- func (of Handler[T]) Filter(filter func(T) T) Handler[T]
- func (of Handler[T]) Handle(in T)
- func (of Handler[T]) If(cond bool) Handler[T]
- func (of Handler[T]) Join(next Handler[T]) Handler[T]
- func (of Handler[T]) Lock() Handler[T]
- func (of Handler[T]) Once() Handler[T]
- func (of Handler[T]) PreHook(prev Handler[T]) Handler[T]
- func (of Handler[T]) RecoverPanic(in T) error
- func (of Handler[T]) Safe() func(T) error
- func (of Handler[T]) Skip(hook func(T) bool) Handler[T]
- func (of Handler[T]) When(cond func() bool) Handler[T]
- func (of Handler[T]) WithLock(mtx *sync.Mutex) Handler[T]
- func (of Handler[T]) WithLocker(mtx sync.Locker) Handler[T]
- func (of Handler[T]) WithRecover(oe Handler[error]) Handler[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Future ¶
type Future[T any] func() T
Future is a basic function for providing a fun-style function type for a function object that will produce an object of the specified type.
func AsFuture ¶
AsFuture wraps a value and returns a future object that, when called, will return the provided value.
func MakeFuture ¶
MakeFuture constructs a Future[T] object from a function object.
func (Future[T]) If ¶
If produces a future that only runs when the condition value is true. If the condition is false, the future will return the zero value of T.
func (Future[T]) Ignore ¶
func (f Future[T]) Ignore() func()
Ignore produces a function that will call the Future but discards the output.
func (Future[T]) Join ¶
Join iteratively merges a collection of future operations.
If any of the futures are nil, the zero value for T is used. The merge function MUST NOT be nil.
func (Future[T]) Lock ¶
Locked returns a wrapped future that ensure that all calls to the future are protected by a mutex.
func (Future[T]) Not ¶
Not produces that only runs when the condition value is false. If the condition is true, the future will return the zero value of T.
func (Future[T]) Once ¶
Once returns a future that will only run the underlying future exactly once.
func (Future[T]) PostHook ¶
PostHook unconditionally runs the provided function after running the future. The hook runs in a defer statement.
func (Future[T]) PreHook ¶
PreHook unconditionally runs the provided function before running and returning the function.
func (Future[T]) RecoverPanic ¶
func (Future[T]) Reduce ¶
Reduce takes the input future, the next future, and merges the results using the merge function.
func (Future[T]) Resolve ¶
func (f Future[T]) Resolve() T
Resolve executes the future and returns its value.
func (Future[T]) Slice ¶
func (f Future[T]) Slice() func() []T
Slice returns a future-like function that wraps the output of the future as the first element in a slice.
func (Future[T]) When ¶
When produces a new future wrapping the input future that executes when the condition function returns true, returning the zero value for T when the condition is false. The condition value is checked every time the future is called.
type Handler ¶
type Handler[T any] func(T)
Handler describes a function that operates on a single object, but returns no output, and is used primarily for side effects, particularly around handling errors or collecting metrics. The Handler implementation here makes it possible to provide panic-safety for these kinds of functions or easily convert to other related types.
func JoinHandlers ¶
JoinHandlers returns a function that combines a collection of handlers.
func NewHandler ¶
NewHandler produces an Handler[T] function as a helper.
func (Handler[T]) All ¶
func (of Handler[T]) All(in ...T)
All processes all inputs with the specified handler.
func (Handler[T]) Capture ¶
func (of Handler[T]) Capture(in T) func()
Capture returns a function that handles the specified value, but only when executed later.
func (Handler[T]) Filter ¶
Filter creates an handler that only executes the root handler Use this to process or transform the input before it is passed to the underlying handler. Use in combination with the Skip function to filter out non-actionable inputs.
func (Handler[T]) Handle ¶
func (of Handler[T]) Handle(in T)
Handler provides a more expository operation to call a handler function.
func (Handler[T]) If ¶
If returns an handler that only executes the root handler if the condition is true.
func (Handler[T]) Join ¶
Join creates an handler function that runs both the root handler and the "next" handler.
func (Handler[T]) Lock ¶
Lock returns an handler that is protected by a mutex. All execution's of the handler are isolated.
func (Handler[T]) Once ¶
Once produces an handler function that runs exactly once, and successive executions of the handler are noops.
func (Handler[T]) PreHook ¶
PreHook provides the inverse operation to Join, running "prev" handler before the base handler.
Returns itself if prev is nil.
func (Handler[T]) RecoverPanic ¶
RecoverPanic runs the handler function with a panic handler and converts a possible panic to an error.
func (Handler[T]) Safe ¶
Safe returns a function that will execute the underlying Handler function. Any panics in the underlying handler are converted to errors.
func (Handler[T]) Skip ¶
Skip runs a check before passing the object to the obsever, when the condition function--which can inspect the input object--returns true, the underlying Handler is called, otherwise, the observation is a noop.
func (Handler[T]) When ¶
When returns an handler function that only executes the handler function if the condition function returns true. The condition function is run every time the handler function runs.
func (Handler[T]) WithLocker ¶
WithLock protects the action of the handler with the provied mutex.