finalizer

package
v0.0.0-...-ae0dd77 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloseFn

type CloseFn func() error

type Finalizer

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

Finalizer implements the defer-close pattern to guarantee: - close is always called exactly once - any error is properly surfaced See more details below: - https://www.digitalocean.com/community/tutorials/understanding-defer-in-go - https://www.joeshaw.org/dont-defer-close-on-writable-files/

func WithClose

func WithClose(close CloseFn) *Finalizer

func WithCloser

func WithCloser(closer io.Closer) *Finalizer

func (*Finalizer) Close

func (f *Finalizer) Close() error

Close should be called at the end of the function. As a result, the error from close is surfaced only when there is no error before Close is called.

func (*Finalizer) Finalize

func (f *Finalizer) Finalize()

Finalize should be called in the defer statement. Any error is ignored.

Jump to

Keyboard shortcuts

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