undo

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(fn func(u Undoer) error) error

Do runs a func with a new Undoer. If the func returns error, all the undo funcs, registered with the Undoer will run in reverse order and all errors will be joined with the main error.

Example
fmt.Println(Do(func(u Undoer) error {
	u.Undo(func() error {
		fmt.Println("undoing")
		return errors.New("undo error")
	})
	fmt.Println("doing")
	return errors.New("do error")
}))
Output:

doing
undoing
do error
undo error

Types

type Undoer

type Undoer interface {
	// Undo registers an undo function.
	Undo(fn func() error)
}

Undoer allows registring undo functions.

Jump to

Keyboard shortcuts

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