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

fulfillment

package
v0.1.64 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package fulfillment provides reusable atomic coordination for keyed claims.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abort

func Abort(err error) error

Abort marks a fulfillment error as lifecycle cancellation. An aborted transaction returns the wrapped error without invoking Rollback.

Types

type Group

type Group[K comparable] struct {
	Key   K
	Count int
}

Group describes one homogeneous claim from a keyed inventory.

type RolledBackError

type RolledBackError struct {
	Cause error
}

RolledBackError reports the original fulfillment failure after Rollback completed successfully. Callers that persist their own failure state can use errors.As to distinguish this expected recovery path from a rollback failure.

func (RolledBackError) Error

func (e RolledBackError) Error() string

func (RolledBackError) Unwrap

func (e RolledBackError) Unwrap() error

type Transaction

type Transaction[K comparable, S any] struct {
	Prepare  func(context.Context, Group[K]) error
	Snapshot func(context.Context, []Group[K]) (S, error)
	Fulfill  func(context.Context, Group[K]) error
	Rollback func(context.Context, S, error) error
}

Transaction coordinates preparation and all-or-nothing fulfillment across multiple keyed groups. Snapshot and rollback are caller-owned because the transaction does not know how inventory is persisted.

func (Transaction[K, S]) Run

func (t Transaction[K, S]) Run(ctx context.Context, groups []Group[K]) error

Run prepares every group, captures a snapshot, and fulfills groups in input order. A fulfillment failure invokes Rollback exactly once. Preparation and snapshot failures happen before any claim and therefore do not roll back.

Jump to

Keyboard shortcuts

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