deferred

package module
v0.0.0-...-57480bf Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: BlueOak-1.0.0 Imports: 0 Imported by: 0

README

error helper for deferred functions

What if you want to defer Close() on an io.WriteCloser, but you don't want to throw away the error?

// Always calls Close() and returns the Close() error if no writes fail
func writeAndClose(output io.WriteCloser, records [][]byte) (err error) {
	defer deferred.FuncErr(output.Close)(&err)
	for _, record := range records {
		_, err = output.Write(record)
		if err != nil {
			return err
		}
	}
	return nil
}

The named result parameter is necessary

See Also

Joe Shaw: Don't defer Close() on writable files

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncErr

func FuncErr(fn func() error) (deferMe func(*error))

Types

This section is empty.

Jump to

Keyboard shortcuts

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