txgroup

package module
v0.0.0-...-4c693ee Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

txgroup

Package txgroup provides a simple way of handling multiple transactions from different databases as if they were only one, facilitating their propagation, cancelation and execution.

Note that it does not guarantee atomicity among transactions, one may succeed and the following one fail, leaving the system with an inconsistent state.

For an example on how to use the package head over to example.

go get -u github.com/GGP1/txgroup

Documentation

Overview

Package txgroup provides a simple way of handling multiple transactions as if they were a single one, helping to propagate, cancel and execute them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, txs ...Tx) (context.Context, context.CancelFunc)

NewContext returns a new context with the transactions stored in it.

Types

type Group

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

Group manages a group of transactions.

func WithContext

func WithContext(ctx context.Context, txs ...Tx) (*Group, context.Context)

WithContext returns a transactions group containing a context with all the transactions stored in it.

func (*Group) AddTx

func (g *Group) AddTx(ctx context.Context, tx Tx) (context.Context, error)

AddTx adds a new transaction to the group.

func (*Group) Commit

func (g *Group) Commit() error

Commit commits all transactions.

func (*Group) Rollback

func (g *Group) Rollback() error

Rollback aborts all transactions.

type Tx

type Tx interface {
	// Commit commits the transaction.
	Commit() error
	// Rollback aborts the transaction.
	Rollback() error
	// Key returns the transaction identifier,
	// it should be unique among the objects satisfying Tx.
	Key() string
	// Weight returns an integer representation of the priority in which the
	// transaction should be executed.
	Weight() uint
}

Tx represents a database transaction.

func TxFromContext

func TxFromContext(ctx context.Context, key string) (Tx, error)

TxFromContext returns a single transaction from the context.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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