tx

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package tx provides transactional request orchestration on top of the event bus.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ReadyFunction

type ReadyFunction func(responses []*model.Message)

ReadyFunction handles the responses collected by a completed transaction.

type Transaction

type Transaction interface {
	// Sends a request to a channel as a part of this transaction.
	SendRequest(channel string, payload any) error
	//  Wait for a store to be initialized as a part of this transaction.
	WaitForStoreReady(storeName string) error
	// Registers a new complete handler. Once all responses to requests have been received,
	// the transaction is complete.
	OnComplete(completeHandler ReadyFunction) error
	// Register a new error handler. If an error is thrown by any of the responders, the transaction
	// is aborted and the error sent to the registered errorHandlers.
	OnError(errorHandler bus.MessageErrorFunction) error
	// Commit the transaction, all requests will be sent and will wait for responses.
	// Once all the responses are in, onComplete handlers will be called with the responses.
	Commit() error
	CommitContext(ctx context.Context) error
}

Transaction batches bus requests and store readiness waits into one commit operation.

func New

func New(eventBus bus.EventBus, storeManager store.Manager, transactionType TransactionType) Transaction

New creates a transaction bound to an event bus and store manager.

type TransactionType

type TransactionType int

TransactionType controls whether a transaction waits synchronously or runs asynchronously.

const (
	// AsyncTransaction sends requests asynchronously and reports completion through callbacks.
	AsyncTransaction TransactionType = iota
	// SyncTransaction sends each request after the previous request has completed.
	SyncTransaction
)

Jump to

Keyboard shortcuts

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