cleanup

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector interface {
	Collect(f func() error)
	JoinTo(dst *error) error
}
Example
package main

import (
	"errors"
	"fmt"

	"github.com/xoctopus/x/misc/cleanup"
)

func main() {

	func() {
		c := cleanup.NewCollector()

		err := fmt.Errorf("main error")

		defer func() {
			fmt.Println(c.JoinTo(&err))
		}()

		c.Collect(func() error { return errors.New("a") })

		c.Collect(func() error { return errors.New("b") })

		c.Collect(func() error { return errors.New("c") })

		c.Collect((&closer{}).Close)

		c.Collect((&closer{"d"}).Close)

		_ = c.JoinTo(&err)
	}()

	func() {
		c := cleanup.NewCollector()

		var err error

		defer func() {
			fmt.Println(c.JoinTo(&err))
		}()
	}()

}

type closer struct{ name string }

func (c *closer) Close() error {
	if len(c.name) > 0 {
		return errors.New(c.name)
	}
	return nil
}
Output:
main error
d
c
b
a
<nil>

func NewCollector

func NewCollector() Collector

Jump to

Keyboard shortcuts

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