event

package
v0.0.0-...-83625b3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2018 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action func()

Action is the simpliest event handler.

It won't receive the event value, and it can't report an error.

func (Action) Handle

func (a Action) Handle(e Event) error

Handle handles an event.

type Dispatcher

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

Dispatcher dispatches an event to its subscribers.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher creates a Dispatcher.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(e Event) []error

Dispatch dispatches an event to the relevant subscribers.

func (*Dispatcher) Subscribe

func (d *Dispatcher) Subscribe(name string, s Subscriber) error

Subscribe subscribes a subscriber to an event type.

type ErrorStrategy

type ErrorStrategy int

ErrorStrategy tells the dispatcher what to do when an error happens.

const (
	// ErrorStrategyIgnore ignores the error. No error will be reported from Dispatch().
	ErrorStrategyIgnore ErrorStrategy = iota
	// ErrorStrategyStop stops at the first error.
	ErrorStrategyStop
	// ErrorStrategyAggregate collects the errors, but keeps processing the subscribers.
	ErrorStrategyAggregate
)

type Event

type Event interface {
	// Name returns the machine name of the event.
	// This function should be idempotent.
	Name() string
	// ErrorStrategy tells the dispatcher how to behave when an error happens.
	// This function should be idempotent.
	ErrorStrategy() ErrorStrategy
}

Event represents the events that will be dispatched to the subscribers.

type Subscriber

type Subscriber interface {
	Handle(e Event) error
}

Subscriber subscribes to an event.

type SubscriberFunc

type SubscriberFunc func(e Event) error

SubscriberFunc is a simple subscriber that is a function.

func (SubscriberFunc) Handle

func (f SubscriberFunc) Handle(e Event) error

Handle handles an event.

Jump to

Keyboard shortcuts

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