quiet

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: MIT Imports: 3 Imported by: 6

README

quiet

Quiet cleanup functions for graceful shutdowns.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(closer io.Closer)

Close quietly invokes the closer. Any errors or panics will be logged by the package logger.

func CloseFunc

func CloseFunc(close func())

CloseFunc quietly invokes the given function. Any panics will be logged by the package logger.

func CloseFuncE

func CloseFuncE(close func() error)

CloseFuncE quietly invokes the given function. Any errors or panics will be logged by the package logger.

func CloseWithTimeout

func CloseWithTimeout(close func(ctx context.Context) error, timeout time.Duration)

CloseWithTimeout quiety invokes the given function with the timeout set on its context. Any errors or panics will be logged by the package logger.

func Noop added in v0.7.0

func Noop() io.Closer

Noop returns a closer that does nothing.

func SetLogger

func SetLogger(logger Logger)

SetLogger sets a panic & error logger for the package rather than the default noop logger. Passing in a nil logger will reset the package logger to default.

Types

type Closer

type Closer struct {
	// contains filtered or unexported fields
}

Closer for when you need to coordinate delayed cleanup.

func (*Closer) Add

func (c *Closer) Add(closers ...io.Closer)

Add multiple closers to be invoked by CloseAll.

See also Close.

func (*Closer) AddFunc

func (c *Closer) AddFunc(closer func())

AddFunc adds a closer function to be invoked by CloseAll.

See also CloseFunc.

func (*Closer) AddFuncE

func (c *Closer) AddFuncE(closer func() error)

AddFuncE adds a closer function to be invoked by CloseAll.

See also CloseFuncE.

func (*Closer) AddTimeout

func (c *Closer) AddTimeout(closer func(ctx context.Context) error, timeout time.Duration)

AddTimeout adds a closer function with a timeout to be invoked by CloseAll.

See also CloseWithTimeout.

func (*Closer) Close

func (c *Closer) Close() error

Close for io.Closer compatibility. Calls CloseAll and returns nil.

func (*Closer) CloseAll added in v0.2.10

func (c *Closer) CloseAll()

CloseAll will call each closer in reverse addition order. This mimics the invocation order of defers in a function.

type Logger

type Logger interface {
	Error(err error)
	Panic(p any)
}

Logger allows logging of errors and panics.

Jump to

Keyboard shortcuts

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