Documentation
¶
Overview ¶
Package failable provides a function that does work with failable chanels already setup.
Index ¶
- Variables
- func Do(fn func(FailFunc)) error
- func DoWithContext(ctx context.Context, fn HandlerFunc) error
- func Run(fn func(FailFunc)) (Completed, Failed)
- func RunSimple(fn func() error) (Completed, Failed)
- func RunSimpleWithContext(ctx context.Context, fn SimpleHandlerFunc) (Completed, Failed)
- func RunWithContext(ctx context.Context, fn HandlerFunc) (Completed, Failed)
- type Completed
- type FailFunc
- type Failed
- type HandlerFunc
- type SimpleHandlerFunc
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNilFailure sent if the error passed to the fail function is nil ErrNilFailure = errors.New("nil failure") )
Functions ¶
func DoWithContext ¶
func DoWithContext(ctx context.Context, fn HandlerFunc) error
DoWithContext performs a run and handles the channel's appropriately
func Run ¶
Run performs the work in a new goroutine
If the fail function is called the goroutine will exit and the failed channel will be signaled with the error.
func RunSimple ¶
RunSimple performs the function in a new goroutine and will fail with returned error if there is one.
func RunSimpleWithContext ¶
func RunSimpleWithContext(ctx context.Context, fn SimpleHandlerFunc) (Completed, Failed)
RunSimpleWithContext performs the function in a new goroutine and will fail with returned error if there is one.
The context is passed to the function.
func RunWithContext ¶
func RunWithContext(ctx context.Context, fn HandlerFunc) (Completed, Failed)
RunWithContext performs the work in a new goroutine passing the context into the handler function.
Types ¶
type Completed ¶
type Completed <-chan struct{}
Completed is the channel this is signaled when the function successfully completes.
type FailFunc ¶
type FailFunc func(error)
FailFunc can be called to fail an operation immediately.
If the failure function is passed a nil error the failed channel will be signaled with ErrCompleted
type Failed ¶
type Failed <-chan error
Failed is the channel this is signaled with the failing error.
type HandlerFunc ¶
HandlerFunc is the main function that is called with a context and the failure function.
type SimpleHandlerFunc ¶
SimpleHandlerFunc allows you to directly return an error instead of calling the failure function.