Help us shape the future of Go! Take the 2026 Go Developer Survey

saga

package
v1.11.9 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package saga provides experimental process-local step coordination with reverse compensation. It is not durable and cannot replace a distributed workflow engine for work that must survive process failure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coordinator

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

Coordinator runs process-local saga steps with reverse compensation. It is not a durable workflow engine and cannot recover work after a process exit.

func NewCoordinator

func NewCoordinator() *Coordinator

NewCoordinator creates a new saga coordinator instance.

func (*Coordinator) AddStep

func (c *Coordinator) AddStep(name string, execute, compensate func(ctx context.Context) error)

AddStep adds a transaction step with an execution func and reverse compensation func.

func (*Coordinator) Execute

func (c *Coordinator) Execute(ctx context.Context) error

Execute runs steps in order and compensates completed steps in reverse order. The returned error includes both the failed step and any compensation failures.

type Step

type Step struct {
	Name       string
	Execute    func(ctx context.Context) error
	Compensate func(ctx context.Context) error
}

Step defines one action and its optional reverse compensation.

Jump to

Keyboard shortcuts

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