event

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event interface{}

Event is the event interface.

type HandlerFunc

type HandlerFunc func(e Event)

HandlerFunc is an event handler func.

type Manager

type Manager interface {
	// Subscribe subscribes a handler to an event type with a priority
	// and returns a func that can be run to unsubscribe the handler.
	//
	// HandlerFunc should return as soon as possible and start long-running tasks in parallel.
	// The Type can be any type, pointer to type or reflect.Type and the handler is only run for
	// the exact type subscribed for.
	//
	// HandlerFunc always gets the fired event of the same subscribed eventType or the same type as
	// represented by reflect.Type.
	Subscribe(eventType interface{}, priority int, fn HandlerFunc) (unsubscribe func())
	// Fire fires an event in the calling goroutine and returns after all subscribers are complete handling it.
	// Any panic by a subscriber is caught so firing the event to the next subscriber can proceed.
	Fire(Event)
	// FireParallel fires an event in a new goroutine B and returns immediately.
	// It optionally runs handlers in goroutine B after all subscribers are done and passes
	// the potentially modified version of the fired event.
	// If an "after" handler returns false or panics no further handlers in the slice are run.
	FireParallel(event Event, after ...HandlerFunc)
	// Wait blocks until no event handlers are running.
	Wait()
}

Manager is an event manager to subscribe, fire events and decouple the event source and sink in a complex system.

var Nop Manager = &nopMgr{}

Nop is an event Manager that does nothing.

func New

func New(log logr.Logger) Manager

New returns a new event Manager optionally using a logger to log handler panics.

type Type

type Type reflect.Type

Type is an event type.

func TypeOf

func TypeOf(i interface{}) (t Type)

TypeOf is a helper func to get the reflect.Type from i. If i is nil returns nil.

Jump to

Keyboard shortcuts

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