batchcloser

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: BSD-3-Clause Imports: 5 Imported by: 0

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 Wrap

func Wrap(close func() error) io.Closer

Wrap can be used wrap close functions in an io.Closer.

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

type CloseError struct {
	Cause  error
	Closer io.Closer
}

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.

Jump to

Keyboard shortcuts

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