Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContext ¶
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 ¶
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 ¶
FromContext returns a pointer to the transactional context if present, or nil if not found.
func (*T) Rollback ¶
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.