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 ¶
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 ¶
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.