event

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Store

func Store(s Source, events ...Event)

Store given events in the given source. In order to use this method, you must embed the `event.Emitter` struct.

Types

type Dispatcher

type Dispatcher interface {
	Dispatch(context.Context, ...Event) error // Dispatch given events to appropriate handlers.
}

Represents an element capable of dispatching domain events somewhere.

func NewInProcessDispatcher

func NewInProcessDispatcher(handlers ...Handler) Dispatcher

Instantiates a dispatcher which will dispatch events synchronously to the given handlers and returns early if an error has been thrown by one handler.

This is the simplest dispatcher I can think of. It is mostly used to trigger usecases on some domain events to make them easier to test and reason about in isolation.

type Emitter

type Emitter struct {
	// contains filtered or unexported fields
}

Implements the Source interface, embed it in your own entities to enable functions such as `Store` and `Unwrap`.

I really like this solution because it does not poluate the domain stuff by exposing methods on entities. You have to explicitly ask for it.

type Event

type Event any

Event triggered by main aggregates. This type is mostly a precaution in case required metadata evolve afterwards.

func Unwrap

func Unwrap(s Source) []Event

Unwrap events from the given source. In order to use this method, you must embed the `event.Emitter` struct.

type Handler

type Handler func(context.Context, Event) error

type Source

type Source interface {
	// contains filtered or unexported methods
}

Represents an event source which contains events before dispatching. Methods are unexported to avoid polluting the domain entities with those considerations for external clients.

You may use `Store` and `Unwrap` to manipulate a struct which embed an `Emitter`.

Jump to

Keyboard shortcuts

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