Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collector ¶
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
Click to show internal directories.
Click to hide internal directories.