manager

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package manager implements a trm.Manager interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainedMW

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

ChainedMW starts transactions in the order given and commit/rollback in reverse order.

WARNING: Rollback of last transactions isn't affected done commits. ChainedMW should be only used if the application can tolerate or recover from an inconsistent state caused by partially committed transactions.

func MustChained

func MustChained(mm []trm.Manager, oo ...Opt) *ChainedMW

MustChained returns ChainedMW if err is nil and panics otherwise.

func NewChained

func NewChained(mm []trm.Manager, _ ...Opt) (*ChainedMW, error)

NewChained creates *ChainedMW or chained trm.Manager.

func (*ChainedMW) Do

func (c *ChainedMW) Do(
	ctx context.Context,
	fn func(ctx context.Context) error,
) error

func (*ChainedMW) DoWithSettings

func (c *ChainedMW) DoWithSettings(
	ctx context.Context,
	s trm.Settings,
	fn func(ctx context.Context) error,
) error

DoWithSettings is an implementation of trm.Manager.

WARNING: trm.CtxKey should not be set in trm.Settings otherwise all trm.Manager would get same trm.Transaction from context.Context.

type Closer

type Closer func(context.Context, interface{}, *error) error

Closer closes trm.Transaction.

type Manager

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

Manager is an implementation of Manager based on storing Transaction in context.Context.

func Must

func Must(f trm.TrFactory, oo ...Opt) *Manager

Must returns Manager if err is nil and panics otherwise.

func New

func New(f trm.TrFactory, oo ...Opt) (*Manager, error)

New creates Manager.

func (*Manager) Do

func (m *Manager) Do(ctx context.Context, fn func(ctx context.Context) error) (err error)

Do processes a transaction inside a closure.

func (*Manager) DoWithSettings

func (m *Manager) DoWithSettings(ctx context.Context, s trm.Settings, fn func(ctx context.Context) error) (err error)

DoWithSettings processes a transaction inside a closure with custom trm.Settings.

func (*Manager) Init

Init creates a context.Context with a trm.Transaction and Closer to finish trm.Transaction. Required to explicitly close the transaction by calling Closer. Nested goroutines would be canceled after the transaction closing by context.CancelFunc.

type Opt

type Opt func(*Manager) error

Opt is a type to configure Manager.

func WithCtxManager

func WithCtxManager(c trm.СtxManager) Opt

WithCtxManager sets trm.Settings for Manager.

func WithLog

func WithLog(l logger) Opt

WithLog sets logger for Manager.

func WithSettings

func WithSettings(s trm.Settings) Opt

WithSettings sets trm.Settings for Manager.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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