cleanup

package
v0.0.0-...-9ec6d29 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 License: Apache-2.0, MIT Imports: 0 Imported by: 0

Documentation

Overview

Package cleanup provides utilities to clean "stuff" on defers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cleanup

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

Cleanup allows defers to be aborted when cleanup needs to happen conditionally. Usage:

	 cu := cleanup.Make(func() { f.Close() })
	 defer cu.Clean() // failure before release is called will close the file.
	 ...
   cu.Add(func() { f2.Close() })  // Adds another cleanup function
   ...
	 cu.Release() // on success, aborts closing the file.
	 return f

func Make

func Make(f func()) Cleanup

Make creates a new Cleanup object.

func (*Cleanup) Add

func (c *Cleanup) Add(f func())

Add adds a new function to be called on Clean().

func (*Cleanup) Clean

func (c *Cleanup) Clean()

Clean calls all cleanup functions in reverse order.

func (*Cleanup) Release

func (c *Cleanup) Release() func()

Release releases the cleanup from its duties, i.e. cleanup functions are not called after this point. Returns a function that calls all registered functions in case the caller has use for them.

Jump to

Keyboard shortcuts

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