cqrs

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrHandlerNil CommandHandler or QueryHandler is nil
	ErrHandlerNil = errors.New("cqrs: handler is nil")

	// ErrRegistered not register CommandHandler or QueryHandler
	ErrRegistered = errors.New("cqrs: handler registered")

	// ErrUnregistered is not register CommandHandler or QueryHandler
	ErrUnregistered = errors.New("cqrs: handler unregistered")

	// ErrArgsNil arguments is nil
	ErrArgsNil = errors.New("cqrs: arguments is nil")

	// ErrBusClosed bus was closed
	ErrBusClosed = errors.New("cqrs: bus was closed")

	// ErrUnimplemented handler is not implement CommandHandler or QueryHandler
	ErrUnimplemented = errors.New("cqrs: handler is not implement CommandHandler or QueryHandler")
)

Functions

This section is empty.

Types

type Bus added in v1.3.2

type Bus interface {

	// RegisterCommand register CommandHandler
	RegisterCommand(handler any) error

	// RegisterQuery register QueryHandler
	RegisterQuery(handler any) error

	// Exec synchronously executes a command
	Exec(ctx context.Context, args any) error

	// Query synchronously executes a query
	Query(ctx context.Context, args any) (any, error)

	// AsyncExec asynchronously executes a command, result in Future
	AsyncExec(ctx context.Context, args any) (Future, error)

	// AsyncQuery asynchronously executes a query, result in Future
	AsyncQuery(ctx context.Context, args any) (Future, error)

	// Close bus gracefully
	Close(ctx context.Context) error
}

Bus is a bus, register CommandHandler and QueryHandler, execute Command and query Query

func NewBus added in v1.3.2

func NewBus(opts ...Option) Bus

type CommandHandler

type CommandHandler[Args any] interface {
	Handle(ctx context.Context, args Args) error
}

CommandHandler is a command handler that to update data.

type CommandHandlerFunc

type CommandHandlerFunc[Args any] func(ctx context.Context, args Args) error

The CommandHandlerFunc type is an adapter to allow the use of ordinary functions as CommandHandler.

func (CommandHandlerFunc[Args]) Handle

func (f CommandHandlerFunc[Args]) Handle(ctx context.Context, args Args) error

Handle calls f(ctx).

type Future added in v1.3.2

type Future interface {
	// Get wait for computation completion, and to retrieve the result of the computation.
	Get(ctx context.Context) (any, error)
}

Future represents the result of an asynchronous computation.

type NoopCommand added in v1.3.2

type NoopCommand[Args any] struct{}

NoopCommand is an CommandHandler that does nothing and returns a nil error.

func (NoopCommand[Args]) Handle added in v1.3.2

func (NoopCommand[Args]) Handle(context.Context, Args) error

type NoopQuery added in v1.2.5

type NoopQuery[Args any, Result any] struct{}

NoopQuery is an QueryHandler that does nothing and returns a nil error.

func (NoopQuery[Args, Result]) Handle added in v1.3.2

func (NoopQuery[Args, Result]) Handle(context.Context, Args) (Result, error)

type Option added in v1.3.2

type Option func(*option)

func Pool added in v1.3.2

func Pool(pool gopher.Gopher) Option

type QueryHandler

type QueryHandler[Args any, Result any] interface {
	Handle(ctx context.Context, args Args) (Result, error)
}

QueryHandler is a query handler that to handlers to read data.

type QueryHandlerFunc

type QueryHandlerFunc[Args any, Result any] func(ctx context.Context, args Args) (Result, error)

The QueryHandlerFunc type is an adapter to allow the use of ordinary functions as QueryHandler.

func (QueryHandlerFunc[Args, Result]) Handle

func (f QueryHandlerFunc[Args, Result]) Handle(ctx context.Context, args Args) (Result, error)

Handle calls f(ctx).

Jump to

Keyboard shortcuts

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