Documentation
¶
Overview ¶
Package fulfillment provides reusable atomic coordination for keyed claims.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.