saga

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package saga implements the Saga pattern for distributed transactions.

It allows defining a sequence of steps where each step has a corresponding compensation. If any step fails, the compensations of all executed steps are triggered in reverse order. It supports tree-structured sagas with conditional execution and retries for compensation.

Package saga provides a simple way to define a step in a sequence of steps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[T any](nodes ...Node[T]) tree[T]

func WithChilds

func WithChilds[T any](childs ...Node[T]) nodeOption[T]

func WithCompensation

func WithCompensation[T any](compensation StepRunner[T]) nodeOption[T]

func WithCondition

func WithCondition[T any](condition func(T) bool) nodeOption[T]

func WithStep

func WithStep[T any](step StepRunner[T]) nodeOption[T]

Types

type Node

type Node[T any] struct {
	// contains filtered or unexported fields
}

func NewNode

func NewNode[T any](opts ...nodeOption[T]) (n Node[T])

func (Node[T]) Compensate

func (n Node[T]) Compensate(ctx context.Context, req T) (T, error)

func (Node[T]) Run

func (n Node[T]) Run(ctx context.Context, req T) (T, error)

type ResultMerger

type ResultMerger[T any] func(ctx context.Context, req []T) (T, error)

type StepRunner

type StepRunner[T any] func(ctx context.Context, req T) (T, error)

func ParallelSteps

func ParallelSteps[T any](mergeStep ResultMerger[T], steps ...StepRunner[T]) StepRunner[T]

ParallelSteps executes the steps in parallel. Use it when you do not need the result of one to execute the next one.

func SerialSteps

func SerialSteps[T any](steps ...StepRunner[T]) StepRunner[T]

SerialSteps executes the steps in serial. Use it when you want to execute steps in serial.

Jump to

Keyboard shortcuts

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