cleanup

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2020 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

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() {
  cleanup
})

... // init structures...

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func If

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

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

func IfNot

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

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

func IfNotPred

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

IfNotPred will run the cleanup function if pred returns false.

func IfPred

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

IfPred will run the cleanup function if pred returns true.

func IgnoreError

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

IgnoreError silently ignores errors in the cleanup function.

func WithError

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

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

Types

type FailClean

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

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

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

func (*FailClean) Cleanup

func (f *FailClean) Cleanup()

Cleanup runs all cleanup handlers in reverse order.

func (*FailClean) Signal

func (f *FailClean) Signal(success bool)

Signal sends a success or fail signal to FailClean.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL