batchcloser

package
v0.9.17 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 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(closeFunc func() error) io.Closer

Wrap can be used to wrap close functions into an io.Closer.

func WrapCancel

func WrapCancel(cancel context.CancelFunc) io.Closer

WrapCancel can be used to wrap a context.CancelFunc into 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.

Jump to

Keyboard shortcuts

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