Documentation
¶
Overview ¶
Package batchcloser provides an object "BatchCloser" that collects multiple io.Closers and closes them all when Closers.Close is called.
It also provides helper methods for wrapping close/cancel functions in io.Closer objects.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WrapCancel ¶
func WrapCancel(cancel context.CancelFunc) io.Closer
WrapCancel can be used to wrap a context.CancelFunc in an io.Closer.
Types ¶
type BatchCloser ¶
type BatchCloser struct {
// contains filtered or unexported fields
}
BatchCloser is a collection of io.Closer objects that are all closed when BatchCloser.Close is called.
func New ¶
func New(closers ...io.Closer) *BatchCloser
New returns a pointer to a new BatchCloser initialized with the given closers.
func (*BatchCloser) Add ¶
func (bc *BatchCloser) Add(closers ...io.Closer)
Add adds the given io.Closer objects to the BatchCloser.
This is not safe to be called concurrently.
func (*BatchCloser) Close ¶
func (bc *BatchCloser) Close() error
Close implements io.Closer and closes all of it's internal io.Closer objects, batching any errors into an errorsbp.Batch.
type CloseError ¶
CloseError is used to wrap the errors returned by the inner closers within a BatchCloser.
It can be used to inspect both the error that was returned and the io.Closer that caused it.
func (CloseError) As ¶
func (err CloseError) As(v interface{}) bool
As implements helper interface for errors.As.
func (CloseError) Error ¶
func (err CloseError) Error() string
Error implements the interface for error.
func (CloseError) Unwrap ¶
func (err CloseError) Unwrap() error
Unwrap implements helper interface for errors.Is.