finalizer

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Deprecated: use github.com/mandelsoft/goutils/finalizer

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Calling1

func Calling1[T any](f func(arg T) error, arg T) func() error

Calling1 can be used with Finalizer.With, to call an error providing function with one argument.

func Calling1V

func Calling1V[T any](f func(arg T), arg T) func() error

Calling1V can be used with Finalizer.With, to call a void function with one argument.

func Calling2

func Calling2[T, U any](f func(arg1 T, arg2 U) error, arg1 T, arg2 U) func() error

func Calling2V

func Calling2V[T, U any](f func(arg1 T, arg2 U), arg1 T, arg2 U) func() error

func Calling3

func Calling3[T, U, V any](f func(arg1 T, arg2 U, arg3 V) error, arg1 T, arg2 U, arg3 V) func() error

func Calling3V

func Calling3V[T, U, V any](f func(arg1 T, arg2 U, arg3 V), arg1 T, arg2 U, arg3 V) func() error

func CallingV

func CallingV(f func()) func() error

func ClosingWith

func ClosingWith[T io.Closer](f *Finalizer, o T) T

ClosingWith can be used add a close request to finalizer in a chained call. Unfortunately it is not possible in Go to define parameterized methods, therefore we cannot directly add this function to the Finalizer type.

func FinalizeException

func FinalizeException(err error) bool

FinalizeException is an exception matcher for nested finalization exceptions.

Types

type Finalizable

type Finalizable interface {
	Finalize() error
}

type FinalizationError

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

func (FinalizationError) Unwrap

func (e FinalizationError) Unwrap() error

type Finalizer

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

Finalizer gathers finalization functions and calls them by calling the Finalize method(s). Add and Finalize may be called in any sequence and number. Finalize just calls the aggregated functions between its last and the actual call. This way it can be used together with defer to clean up stuff when leaving a function and combine it with controlled intermediate cleanup needed, for example as part of a loop block.

func (*Finalizer) BindToReader

func (f *Finalizer) BindToReader(r io.ReadCloser, msg ...string) io.ReadCloser

BindToReader moves the pending finalizations to the close action of a reader closer.

func (*Finalizer) CatchException

func (f *Finalizer) CatchException(matchers ...exception.Matcher) *Finalizer

CatchException marks the finalizer to catch exceptions. This must be combined with error propagating defers.

func (*Finalizer) Close

func (f *Finalizer) Close(c io.Closer, msg ...string) *Finalizer

Close will finalize the given object by calling its Close function when the finalizer is finalized.

func (*Finalizer) Closef added in v0.5.0

func (f *Finalizer) Closef(c io.Closer, msg string, args ...interface{}) *Finalizer

Closef will finalize the given object by calling its Close function when the finalizer is finalized and annotates an error with the given formatted message.

func (*Finalizer) Finalize

func (f *Finalizer) Finalize() (err error)

Finalize calls all finalizations in the reverse order of their registration and incorporates catched exceptions.

func (*Finalizer) FinalizeWithErrorPropagation

func (f *Finalizer) FinalizeWithErrorPropagation(efferr *error)

FinalizeWithErrorPropagation calls all finalizations in the reverse order of their registration and propagates a potential error to the given error variable incorporating an already existing error. This is especially intended to be used in a deferred mode to adapt the error code of a function to incorporate finalization errors.

func (*Finalizer) FinalizeWithErrorPropagationf

func (f *Finalizer) FinalizeWithErrorPropagationf(efferr *error, msg string, args ...interface{})

FinalizeWithErrorPropagationf calls all finalizations in the reverse order of their registration and propagates a potential error to the given error variable incorporating an already existing error. This is especially intended to be used in a deferred mode to adapt the error code of a function to incorporate finalization errors. The final error will be wrapped by the given common context.

func (*Finalizer) Include

func (f *Finalizer) Include(fi *Finalizer) *Finalizer

Include includes the finalization of a given finalizer.

func (*Finalizer) Length

func (f *Finalizer) Length() int

func (*Finalizer) Lock

func (f *Finalizer) Lock(locker sync.Locker, msg ...string) *Finalizer

Lock locks a given Locker and unlocks it again during finalization.

func (*Finalizer) Nested

func (f *Finalizer) Nested() *Finalizer

Nested returns a linked finalizer usable in a nested block, which can be separately finalized. It is intended for sequential use, for example in a for loop. Successive calls will provide the same finalizer. The nested finalizer SHOULD be finalized at the end of its scope before it is requested, again, for the next nested usage.

func (*Finalizer) New

func (f *Finalizer) New() *Finalizer

New return a new finalizer included in the actual one.

func (*Finalizer) ThrowFinalize

func (f *Finalizer) ThrowFinalize()

ThrowFinalize executes the finalization and in case of an error it throws the error to be catched by an outer finalize or other error handling with the exception package. It is explicitly useful fo finalize nested finalizers in loops.

func (*Finalizer) With

func (f *Finalizer) With(fi func() error, msg ...string) *Finalizer

func (*Finalizer) WithVoid

func (f *Finalizer) WithVoid(fi func(), msg ...string) *Finalizer

WithVoid registers a simple function to be called on finalization.

Jump to

Keyboard shortcuts

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