txndefer

package
v0.0.0-...-d3da680 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0, Apache-2.0 Imports: 3 Imported by: 3

Documentation

Overview

Package txndefer implements a filter that calls best-effort callbacks on successful transaction commits.

Useful when an activity inside a transaction has some best-effort follow up that should be done once the transaction has successfully landed.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Defer

func Defer(ctx context.Context, cb func(context.Context))

Defer schedules `cb` for execution when the current transaction successfully lands.

Intended for a best-effort non-transactional follow up to a successful transaction. Note that in presence of failures there's no guarantee the callback will be called. For example, the callback won't ever be called if the process crashes right after landing the transaction. Or if the transaction really landed, but RunInTransaction finished with "deadline exceeded" (or some similar) error.

Callbacks are executed sequentially in the reverse order they were deferred. They receive the non-transactional version of the context initially passed to RunInTransaction so that they inherit the deadline of the entire transaction.

Panics if the given context is not transactional or there's no txndefer filter installed.

func FilterRDS

func FilterRDS(ctx context.Context) context.Context

FilterRDS installs the datastore filter into the context.

Example
ctx := FilterRDS(memory.Use(context.Background()))

datastore.RunInTransaction(ctx, func(ctx context.Context) error {
	Defer(ctx, func(context.Context) { fmt.Println("1") })
	Defer(ctx, func(context.Context) { fmt.Println("2") })
	return nil
}, nil)
Output:

2
1

Types

This section is empty.

Jump to

Keyboard shortcuts

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