package cleanup
import "gvisor.dev/gvisor/pkg/cleanup"
Package cleanup provides utilities to clean "stuff" on defers.
Index ¶
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.
Source Files ¶
cleanup.go
- Version
- v0.0.0-20250605235530-a6711d1e1dc6 (latest)
- Published
- Jun 5, 2025
- Platform
- linux/amd64
- Last checked
- 4 hours ago –
Tools for package owners.