gae: go.chromium.org/gae/filter/txndefer Index | Examples | Files

package txndefer

import "go.chromium.org/gae/filter/txndefer"

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

Package Files

filter.go

func Defer Uses

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 Uses

func FilterRDS(ctx context.Context) context.Context

FilterRDS installs the datastore filter into the context.

Code:

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

Package txndefer imports 3 packages (graph) and is imported by 1 packages. Updated 2020-07-28. Refresh now. Tools for package owners.