action

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2016 License: MIT Imports: 3 Imported by: 36

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRollbackFailed = errs.NewError(
	"Roll back changes", errors.New("failed to roll back changes"))
View Source
var Noop = ActionFunc(func() error { return nil })

Functions

func RollbackOnError added in v0.8.0

func RollbackOnError(err *error, action Action)

RollbackOnError is equivalent to RollbackTaskOnError(err, "", action).

func RollbackTaskOnError added in v0.8.0

func RollbackTaskOnError(err *error, task string, action Action)

RollbackTaskOnError wraps an ActionChain to perform a rollback on error.

Types

type Action

type Action interface {
	Rollback() error
}

type ActionChain added in v0.9.0

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

func NewActionChain added in v0.9.0

func NewActionChain() *ActionChain

func (*ActionChain) Push added in v0.9.0

func (chain *ActionChain) Push(action Action)

func (*ActionChain) PushTask added in v0.9.0

func (chain *ActionChain) PushTask(task string, action Action)

func (*ActionChain) Rollback added in v0.9.0

func (chain *ActionChain) Rollback() error

func (*ActionChain) RollbackOnError added in v0.9.0

func (chain *ActionChain) RollbackOnError(err *error)

RollbackOnError is supposed to be called using defer:

defer chain.RollbackOnError(&err)

Then it is visible why *error is being passed in. The args are bound when this line is encountered, so it would not be set to a non-nil error in case the error is set later. That is why we pass a pointer so that err can be checked when the deferred function is actually called.

type ActionFunc

type ActionFunc func() error

func (ActionFunc) Rollback

func (action ActionFunc) Rollback() error

Jump to

Keyboard shortcuts

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