Documentation ¶
Overview ¶
Package guard contains middleware capable to protect execution of flow from crashing or from unpredicted behavior.
Index ¶
- func Cancel(data interface{}) floc.Job
- func Complete(data interface{}) floc.Job
- func Deadline(when WhenDeadlineFunc, id interface{}, job floc.Job) floc.Job
- func Fail(data interface{}, err error) floc.Job
- func IgnorePanic(job floc.Job) floc.Job
- func OnDeadline(when WhenDeadlineFunc, id interface{}, job floc.Job, ...) floc.Job
- func OnPanic(job floc.Job, panicTrigger PanicTrigger) floc.Job
- func OnTimeout(when WhenTimeoutFunc, id interface{}, job floc.Job, ...) floc.Job
- func Panic(job floc.Job) floc.Job
- func Resume(mask floc.ResultMask, job floc.Job) floc.Job
- func Timeout(when WhenTimeoutFunc, id interface{}, job floc.Job) floc.Job
- type PanicTrigger
- type TimeoutTrigger
- type WhenDeadlineFunc
- type WhenTimeoutFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cancel ¶
func Cancel(data interface{}) floc.Job
Cancel cancels execution of the flow with the data given.
func Complete ¶
func Complete(data interface{}) floc.Job
Complete completes execution of the flow with the data given.
func Deadline ¶
func Deadline(when WhenDeadlineFunc, id interface{}, job floc.Job) floc.Job
Deadline protects the job from doing the job after the deadline. The job is run in it's own goroutine while the current goroutine waits until the job finished or the deadline came or the flow is finished.
func Fail ¶
func Fail(data interface{}, err error) floc.Job
Fail cancels execution of the flow with the data and error given.
func IgnorePanic ¶
func IgnorePanic(job floc.Job) floc.Job
IgnorePanic protects the job from falling into panic. On panic the panic will be ignored. Guarding the job from falling into panic is effective only if the job runs in the current goroutine.
func OnDeadline ¶
func OnDeadline(when WhenDeadlineFunc, id interface{}, job floc.Job, timeoutTrigger TimeoutTrigger) floc.Job
OnDeadline protects the job from doing the job after deadline. In addition it takes TimeoutTrigger func which called if time is out. The job is run in it's own goroutine while the current goroutine waits until the job finished or the deadline came or the flow is finished.
func OnPanic ¶
func OnPanic(job floc.Job, panicTrigger PanicTrigger) floc.Job
OnPanic protects the job from falling into panic. In addition it takes PanicTrigger func which is called in case of panic. Guarding the job from falling into panic is effective only if the job runs in the current goroutine.
func OnTimeout ¶
func OnTimeout(when WhenTimeoutFunc, id interface{}, job floc.Job, timeoutTrigger TimeoutTrigger) floc.Job
OnTimeout protects the job from taking too much time on execution. In addition it takes TimeoutTrigger func which called if time is out. The job is run in it's own goroutine while the current goroutine waits until the job finished or time went out or the flow is finished.
func Panic ¶
func Panic(job floc.Job) floc.Job
Panic protects the job from falling into panic. On panic the flow will be canceled with the ErrPanic result. Guarding the job from falling into panic is effective only if the job runs in the current goroutine.
func Resume ¶
func Resume(mask floc.ResultMask, job floc.Job) floc.Job
Resume resumes execution of the flow possibly finished by the job. If the mask is empty execution will be resumed regardless the reason it was finished. Otherwise execution will be resumed if the reason it finished with is masked.
func Timeout ¶
func Timeout(when WhenTimeoutFunc, id interface{}, job floc.Job) floc.Job
Timeout protects the job from taking too much time on execution. The job is run in it's own goroutine while the current goroutine waits until the job finished or time went out or the flow is finished.
Types ¶
type PanicTrigger ¶
type PanicTrigger func(ctx floc.Context, ctrl floc.Control, v interface{})
PanicTrigger is triggered when the goroutine state is recovered after panic.
type TimeoutTrigger ¶
type TimeoutTrigger func(ctx floc.Context, ctrl floc.Control, id interface{})
TimeoutTrigger triggers when the execution of the job timed out.
type WhenDeadlineFunc ¶
WhenDeadlineFunc calculates the exact deadline passed in Deadline guards. The implementation may use the state and the id for accurate calculation of the deadline.
func ConstDeadline ¶
func ConstDeadline(deadline time.Time) WhenDeadlineFunc
ConstDeadline returns constant deadline.
func DeadlineIn ¶
func DeadlineIn(delay time.Duration) WhenDeadlineFunc
DeadlineIn calculates the deadline in the future with constant delay from now.
type WhenTimeoutFunc ¶
WhenTimeoutFunc calculates the exact timeout passed in Timeout guards. The implementation may use the state and the id for accurate calculation of the timeout.
func ConstTimeout ¶
func ConstTimeout(timeout time.Duration) WhenTimeoutFunc
ConstTimeout returns constant timeout.