Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithCancel ¶ added in v1.1.0
func ContextWithCancel() (context.Context, context.CancelFunc)
ContextWithCancel returns a new context.Context impl with cancel.
Types ¶
type FuncRunner ¶ added in v1.1.0
type FuncRunner struct { // HandOff is the time after which a blocking function will be considered handed off HandOff time.Duration // ErrorHandler is the function that errors are passed to when encountered by the // provided function. This can be used both for logging, and for error filtering ErrorHandler func(err error) error // contains filtered or unexported fields }
FuncRunner provides a means of managing long-running functions e.g. main logic loops.
func (*FuncRunner) Err ¶ added in v1.1.0
func (r *FuncRunner) Err() error
Err returns the last-set error value.
func (*FuncRunner) Go ¶ added in v1.1.0
func (r *FuncRunner) Go(fn func(ctx context.Context) error) bool
Go will attempt to run 'fn' asynchronously. The provided context is used to propagate requested cancel if FuncRunner.Stop() is called. Any returned error will be passed to FuncRunner.ErrorHandler for filtering/logging/etc. Any blocking functions will be waited on for FuncRunner.HandOff amount of time before considering the function as handed off. Returned bool is success state, i.e. returns true if function is successfully handed off or returns within hand off time with nil error.
func (*FuncRunner) Stop ¶ added in v1.1.0
func (r *FuncRunner) Stop() bool
Stop will cancel the context supplied to the running function.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides a means of tracking a single long-running service, provided protected state changes and preventing multiple instances running. Also providing service state information.
func (*Service) Done ¶
func (svc *Service) Done() <-chan struct{}
Done returns a channel that's closed when Service.Stop() is called. It is the same channel provided to the currently running service function.
func (*Service) Run ¶
Run will run the supplied function until completion, use given context to propagate cancel. Immediately returns false if the Service is already running, and true after completed run.