cleanup

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package cleanup provides functionality for executing cleanup functions.

Index

Constants

This section is empty.

Variables

View Source
var Nop = func() error { return nil }

Nop is a no-op cleanup.Func.

Functions

This section is empty.

Types

type Cleanup

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

Cleanup encapsulates a slice of cleanup funcs. The funcs are executed by Run in reverse order to which they are added. Cleanup is safe for concurrent use.

func New

func New() *Cleanup

New returns a new Cleanup instance.

func (*Cleanup) Add

func (cu *Cleanup) Add(fn func()) *Cleanup

Add adds a cleanup func.

func (*Cleanup) AddC

func (cu *Cleanup) AddC(c io.Closer) *Cleanup

AddC adds c.Close as a cleanup func. This method is no-op if c is nil.

func (*Cleanup) AddE

func (cu *Cleanup) AddE(fn func() error) *Cleanup

AddE adds an error-returning cleanup func.

func (*Cleanup) Append

func (cu *Cleanup) Append(c *Cleanup) *Cleanup

Append c's cleanup funcs to cu.

func (*Cleanup) Len

func (cu *Cleanup) Len() int

Len returns the count of cleanup funcs.

func (*Cleanup) Run

func (cu *Cleanup) Run() error

Run executes the cleanup funcs in reverse order to which they were added. All funcs are executed, even in the presence of an error from a func. Any errors are combined into a single error. The set of cleanup funcs is removed when Run returns.

TODO: Consider renaming Run to Close so that Cleanup implements io.Closer?

Jump to

Keyboard shortcuts

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