errs

package module
v0.0.0-...-24c3d1d Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2018 License: MIT Imports: 0 Imported by: 5

README

errs

convenience wrapper for chaining multiple error returning functions when you do not need to handle the errors separately.

Documentation

Usage

var e errs.Group

// add couple of functions
e.Add(func() error { ... })
e.Defer(func() { ... }) // executes after other functions
e.Add(func() error { ... })
e.Add(func() error { ... })
e.Final(func() { ... }) // executes even if error is returned

// execute them
if err := e.Exec(); err != nil {
    // handle error
}

Documentation

Overview

Package errs is a convenience wrapper for chaining multiple error returning functions when you do not need to handle the errors separately.

var e errs.Group

// add couple of functions
e.Add(func() error { ... })
e.Defer(func() { ... }) // executes after other functions
e.Add(func() error { ... })
e.Add(func() error { ... })
e.Final(func() { ... }) // executes even if error is returned

// execute them
if err := e.Exec(); err != nil {
    // handle error
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

Group is a group of functions. Empty value of Group is usable.

func (*Group) Add

func (g *Group) Add(f func() error)

Add adds f to the group of functions. Functions are executed FIFO.

func (*Group) Defer

func (g *Group) Defer(f func())

Defer adds f to the group of deferred functions. Similar to Add, Defer can be called multiple times to add more defer functions. Defer functions are executed LIFO.

func (Group) Exec

func (g Group) Exec() error

Exec runs all functions then defer functions, stops on the first that errored and returns the error occurred. If no error is encountered, returns nil. If an error is returned, defer functions preceding the error returning function are executed.

func (*Group) Final

func (g *Group) Final(f func())

Final adds a function that is guaranteed to be executed even if an error is returned. Final functions are executed FIFO.

Jump to

Keyboard shortcuts

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