actionrollback

package
v3.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Len

func Len(ctx context.Context) int

func NewContext

func NewContext(ctx context.Context) context.Context

NewContext initializes a new transactional context and embeds it into the provided context.Context. This allows associating a rollback stack with a context for managing transactional operations.

Parameters:

ctx: The base context.Context to which the transactional context will be
     added.

Returns:

context.Context: A new context with the transactional context embedded as
                 a value.

func Register

func Register(ctx context.Context, fn func(ctx context.Context) error)

Register adds a rollback function to the transactional context's stack. If the transactional context is not present in the provided context, the function does nothing.

Parameters:

ctx: The context.Context containing the transactional context.
fn:  The function to be added to the rollback stack. It takes a
     context.Context as input and returns an error during execution.

Behavior:

  • If a transactional context (T) is found in the given context, the function is added to its stack.
  • If no transactional context is found, the function does nothing.

Types

type T

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

T represents a transactional context that maintains a stack of functions to be executed during rollback. Each function in the stack takes a context.Context as input and returns an error.

func FromContext

func FromContext(ctx context.Context) *T

FromContext returns a pointer to the transactional context if present, or nil if not found.

func (*T) Rollback

func (t *T) Rollback(ctx context.Context) error

Rollback iterates over a stack of functions in reverse order and executes them. If any function returns an error, the rollback halts, and the error is returned.

Parameters:

ctx: The context.Context instance to pass to each function in the stack.

Returns:

	error: Returns an error if any function in the stack fails during execution,
        or nil if all functions complete successfully.

Jump to

Keyboard shortcuts

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