mediator

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: Apache-2.0 Imports: 3 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dispatch

func Dispatch(ev Event)

func SetDefault

func SetDefault(m Mediator)

func Subscribe

func Subscribe(hdl EventHandler)

Types

type Event

type Event interface {
	Kind() EventKind
}

Event 事件接口.

type EventCollection

type EventCollection interface {
	Add(Event)
	Raise(Mediator)
}

func NewEventCollection

func NewEventCollection() EventCollection

type EventHandler

type EventHandler interface {
	Listening() []EventKind
	Handle(context.Context, Event)
}

type EventKind

type EventKind string

EventKind 事件类型描述.

type InMemMediator

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

InMemMediator is a simple in-memory mediator implementation.

func (*InMemMediator) Dispatch

func (m *InMemMediator) Dispatch(ev Event)

Dispatch dispatches an event to the mediator.

func (*InMemMediator) Subscribe

func (m *InMemMediator) Subscribe(hdl EventHandler)

Subscribe registers an event handler to the mediator.

func (*InMemMediator) WithGenContext added in v0.5.11

func (m *InMemMediator) WithGenContext(fn func(ctx context.Context, ev Event) context.Context)

WithGenContext present a function to generate a new context for each handler.

func (*InMemMediator) WithOrphanEventHandler

func (m *InMemMediator) WithOrphanEventHandler(fn func(Event))

WithOrphanEventHandler present a function to handle the event when no handler is found.

func (*InMemMediator) WithTimeout added in v0.5.11

func (m *InMemMediator) WithTimeout(timeout time.Duration)

WithTimeout present a timeout for each handler.

type Mediator

type Mediator interface {
	Dispatch(Event)
	Subscribe(EventHandler)
}

Mediator is the interface that wraps the methods of a mediator.

func Default

func Default() Mediator

func NewInMemMediator

func NewInMemMediator(opt Options) Mediator

type Options

type Options struct {
	Timeout    string `json:"timeout" yaml:"timeout" toml:"timeout"`
	Concurrent int    `json:"concurrent" yaml:"concurrent" toml:"concurrent"`
}

Options is the options for the mediator.

Jump to

Keyboard shortcuts

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