reverter

package
v0.0.0-...-036eace Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2020 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RevertFunc

type RevertFunc func() error

RevertFunc describes a function used to revert an operation

type Reverter

type Reverter struct {
	// contains filtered or unexported fields
}

Reverter provides functionality to automatically revert a set of executed operations. It can be used this way:

r := reverter.New() defer r.Finish()

doOperation()

r.Add(func() error {
  revertOperation()
  return nil
})
if err := doOtherOperation(); err != nil {
  return err
}

r.Defuse()

func New

func New() *Reverter

New constructs a new reverter.

func (*Reverter) Add

func (r *Reverter) Add(f ...RevertFunc)

Add adds a new revert function to the reverter which will be called when Finish() is called unless the reverter gets defused.

func (*Reverter) Defuse

func (r *Reverter) Defuse()

Defuse defuses the reverter. If defused none of the added revert functions will be called when Finish() is invoked.

func (*Reverter) Finish

func (r *Reverter) Finish()

Finish invokes all added revert functions if the reverter was not defused.

Jump to

Keyboard shortcuts

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