handler

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRunning = errors.New("event handler is already running")

ErrRunning is returned when trying to run a *Handler that is already running.

Functions

This section is empty.

Types

type Handler

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

A Handler asynchronously handles published events.

var bus event.Bus
h := handler.New(bus)
event.HandleWith(h, func(evt event.Of[FooData]) {...}, "foo")
event.HandleWith(h, func(evt event.Of[BarData]) {...}, "bar")

errs, err := h.Run(context.TODO())

func New

func New(bus event.Bus, opts ...Option) *Handler

New returns an event handler for published events.

func (*Handler) Context

func (h *Handler) Context() context.Context

Context returns the context that was passed to h.Run(). If h.Run() has not been called yet, nil is returned.

func (*Handler) RegisterEventHandler

func (h *Handler) RegisterEventHandler(name string, fn func(event.Event))

RegisterEventHandler registers the handler for the given event. Events must be registered before h.Run() is called. events that are registered after h.Run() has been called, won't be handled.

func (*Handler) Run

func (h *Handler) Run(ctx context.Context) (<-chan error, error)

Run runs the handler until ctx is canceled.

func (*Handler) Running

func (h *Handler) Running() bool

Running returns whether the handler is currently running.

type Option

type Option func(*Handler)

Option is a handler option.

func WithStore

func WithStore(store event.Store) Option

WithStore returns an Option that makes a Handler query the registered events from the provided store on startup and handle them as if they were published over the underlying event bus. This allows to handle "past" events on startup.

Jump to

Keyboard shortcuts

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