beats: Index | Files

package cleanup

import ""

Package cleanup provides common helpers for common cleanup patterns on defer

Use the helpers with `defer`. For example use IfNot with `defer`, such that cleanup functions will be executed if `check` is false, no matter if an error has been returned or an panic has occured.

initOK := false
defer cleanup.IfNot(&initOK, func() {

... // init structures...

initOK = true // notify handler cleanup code must not be executed


Package Files

cleanup.go multi.go

func If Uses

func If(check *bool, cleanup func())

If will run the cleanup function if the bool value is true.

func IfNot Uses

func IfNot(check *bool, cleanup func())

IfNot will run the cleanup function if the bool value is false.

func IfNotPred Uses

func IfNotPred(pred func() bool, cleanup func())

IfNotPred will run the cleanup function if pred returns false.

func IfPred Uses

func IfPred(pred func() bool, cleanup func())

IfPred will run the cleanup function if pred returns true.

func IgnoreError Uses

func IgnoreError(cleanup func() error) func()

IgnoreError silently ignores errors in the cleanup function.

func WithError Uses

func WithError(fn func(error), cleanup func() error) func()

WithError returns a cleanup function calling a custom handler if an error occured.

type FailClean Uses

type FailClean struct {
    // contains filtered or unexported fields

FailClean keeps track of functions to be executed of FailClean did not receive a success signal.

func (*FailClean) Add Uses

func (f *FailClean) Add(fn func())

Add adds another cleanup handler. The last added handler will be run first.

func (*FailClean) Cleanup Uses

func (f *FailClean) Cleanup()

Cleanup runs all cleanup handlers in reverse order.

func (*FailClean) Signal Uses

func (f *FailClean) Signal(success bool)

Signal sends a success or fail signal to FailClean.

Updated 2020-03-16. Refresh now. Tools for package owners.